Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qHRRa-0006wP-49 for pgsql-sql@arkaria.postgresql.org; Thu, 06 Jul 2023 16:02:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qHRRY-0001ml-NQ for pgsql-sql@arkaria.postgresql.org; Thu, 06 Jul 2023 16:02:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qHRRY-0001mb-CO for pgsql-sql@lists.postgresql.org; Thu, 06 Jul 2023 16:02:56 +0000 Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qHRRU-002ZLD-Vc for pgsql-sql@lists.postgresql.org; Thu, 06 Jul 2023 16:02:55 +0000 Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-51e29913c35so1310434a12.0 for ; Thu, 06 Jul 2023 09:02:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688659372; x=1691251372; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=rGCZmRDVQwyXjXrc3KubfOAvqxlNunnNXIhqNeeFQxs=; b=AB8/+gPdaAzuh2P+sTL5gxE0cirlZsK5nyk4o58jkuX132uY5oesgX7xwbsUlgli0L 1KVWuCN33FqY0YVNlxn9kC/gMa19x3B+7wHFj5U5gFmQBjM6OjbLtNbntKPoHRY4vZ9A +0ApwKsyluLMNKnJKvayvgaiXzQ+41jfqc4/dTlOs9fdw2hs1QxrQcSlzZnZgo1Q2av4 bjopbHjbg71mDbx2s0WhR1NWigj+ICpNcBfiB9r1LNKg3U0QD70zqx+jQCbjnRfkG/OD HXqt8WVCuw0gJjpfi7nmeK5tMcyM4oIC6RABhqNIAnYW2Xl2/xhz9/l0t3BHimZ800os dPnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688659372; x=1691251372; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=rGCZmRDVQwyXjXrc3KubfOAvqxlNunnNXIhqNeeFQxs=; b=XSCWCj90Jxh+M1wwEpJ0ft2Deb1+X0H+0OAXqG0e2CnLwnv0Egn+dxFEM719ZnoCTu qGkRKn1M7qwCKvcL0SEmeT2xWp16StdMYjT5S6Ru09vNjmlyYsJUj/QVt+p35VpEA4YM q6YVirZ49kHBuDT1gXshCyRcA4XB0HE4dQDRhcfVXx3jXo6uzXArlo2/WZT0o0oxec7q WKrBWN6LUh7s3EdEPkeS6GC/Zn8WJnj+iJu02SgBSnGth1pdbwR0kS49Y6QH7XhbL6Gg 2It35B5tkmxUnphSOfzcXKzBqzMhgx2Ahjt/TEdD9K4Y4/c+lASZN8mfhfO8meeDx7FO xqAQ== X-Gm-Message-State: ABy/qLbPw5PmAYQ3iqcLn161Db84/1n1l30WMFhn89lTQoRWOnYeg/wG GcOjEQRG7ZNzlDlm+XA/54oDm0ygY6WaybNsqlY= X-Google-Smtp-Source: APBJJlE3KOzuU+Y7D8xfqzoJ7GYcwQg6zzC+/5ImiPv1W4BW+WdMXZepVbZtYDgoTVVpTkSYMvAOL72TNRpITvEfyJQ= X-Received: by 2002:a17:906:7489:b0:993:c2a1:6dc5 with SMTP id e9-20020a170906748900b00993c2a16dc5mr995009ejl.72.1688659371695; Thu, 06 Jul 2023 09:02:51 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Shaozhong SHI Date: Thu, 6 Jul 2023 17:02:40 +0100 Message-ID: Subject: Re: How to select the last value/row? To: "David G. Johnston" Cc: pgsql-sql Content-Type: multipart/alternative; boundary="000000000000ff240905ffd3a52f" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000ff240905ffd3a52f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, 6 Jul 2023 at 16:51, David G. Johnston wrote: > On Thu, Jul 6, 2023 at 8:47=E2=80=AFAM Shaozhong SHI > wrote: > >> Given, >> ID >> 5 >> 4 >> 3 >> 3 >> 2 >> 1 >> >> >> How to select the last one, to end up with >> >> 1 >> >> In Python, there are ways to handle ordered list. >> >> In Postgres, is there something similar? >> > > ORDER BY ASC so the "last item" appears first, then "LIMIT 1" > > David J. > How about ID 5 4 3 3 2 3 The last is 3. Regards, David --000000000000ff240905ffd3a52f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Thu, 6 Jul 2023 at 16:51, David G.= Johnston <david.g.johnsto= n@gmail.com> wrote:
On Thu, Jul 6, 2023 at 8:47=E2=80=AFAM Shaozhong SHI <shishaozhong@gmail.com>= ; wrote:
Given,
ID
5=
4
3
3
2
1

=

How to select the last one, to end up with
<= div>
1

In Python, there are ways to = handle ordered list.

In Postgres, is there somethi= ng similar?

ORDER BY ASC so the "last item" appear= s first, then "LIMIT 1"

David J.


How about=C2=A0
ID
5
4
3
3
2
3

The last is 3.

Regards,

David=C2=A0
--000000000000ff240905ffd3a52f--