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 1qHRGa-0006Mk-Ea for pgsql-sql@arkaria.postgresql.org; Thu, 06 Jul 2023 15:51:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qHRGZ-0004Ly-41 for pgsql-sql@arkaria.postgresql.org; Thu, 06 Jul 2023 15:51:35 +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 1qHRGY-0004Lp-Rj for pgsql-sql@lists.postgresql.org; Thu, 06 Jul 2023 15:51:34 +0000 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qHRGS-002ZGb-1m for pgsql-sql@lists.postgresql.org; Thu, 06 Jul 2023 15:51:34 +0000 Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-98de21518fbso109145866b.0 for ; Thu, 06 Jul 2023 08:51:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688658687; x=1691250687; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=jhArUKBQQ1cbWCZ7MOdIlfnlpnBbwq5QvGCEXivkp7M=; b=ScG9G8HTr3xoPiD9D2IXWMR8EYymQ7aapj4f5czqThpu/EHrHoWMNXIS3hU4oathNo AeJy7LAkNigPK6d/BPusmles2JhrVy9F5ucQWNipp3j2r6H9v1nJdJ2wSg0sTNalJWBV qmIE2o4FRuu+vm2XhBKclXXyMnqAmxhIb7+Odgx4DYrzyhGAbZhLCyAYbIMQLkIv4MCf dUbAm4J7EgNpud1Oc7JmXUBsmsZEqqbZrhnI/GVbWMqyyPyWQe8JVA7uXKb+G7mK0z7W BqwkpLWFQR0Ovaa/w4JGrgFCGdIIHzc6W4NdosB5RxxIq82FEhMx32s0qF0zC+QuOMat CvgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688658687; x=1691250687; 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=jhArUKBQQ1cbWCZ7MOdIlfnlpnBbwq5QvGCEXivkp7M=; b=SElU/uGy0hPFKFEPKp7RTISpVi8RRUNsdD3rge+V+0A0xp0ZjbUVxD7c3BIuJpLVXB lqKhG+y/l9Qu3fmXXS25tdGfxYm4wSpZHMIXiAq2ZLY6/c0nMPL7dfhHdFyl+FSgK38n k/khg5wsG4E2C04XjLZ81qsKtZK9sDje3pbzTBwMIG4lVVe9EkJHZhyxK7N+N94X8dlV mZXM/p60yV2LZYJ/Y+482rWU0hfuS6933xW5SRnckoVh2KpKJBGrvTAIHpIu49fnpkpU UMlsrEFOz5TsRnipwYagE9LCNK+LPdA/O4ZjjCQ/6tC4goSHZpq3AwVoPMT5prPCYpNy /4JQ== X-Gm-Message-State: ABy/qLZDvvWCBp8Vr4pAo/LhcAR8sWJcIrN2o1KoOhT7ELfpJ3bEhEHw 3OUzwaWJ+PMS9le4pH/Wa95P8B7lNvWRYfIPECM= X-Google-Smtp-Source: APBJJlFt8Ea0JGaXSl8lMV/eds4pI/xy+Gn/IUYZ8pvD6gjHqmSg4nCmTOrVO1dGampbb4KQQOBy0gd0pHKxq7ErXT8= X-Received: by 2002:a17:906:728e:b0:993:c48f:184b with SMTP id b14-20020a170906728e00b00993c48f184bmr632024ejl.15.1688658686515; Thu, 06 Jul 2023 08:51:26 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: "David G. Johnston" Date: Thu, 6 Jul 2023 08:51:09 -0700 Message-ID: Subject: Re: How to select the last value/row? To: Shaozhong SHI Cc: pgsql-sql Content-Type: multipart/alternative; boundary="000000000000281e4305ffd37dff" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000281e4305ffd37dff Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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. --000000000000281e4305ffd37dff Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Thu, Jul 6, 2023 at 8:47=E2=80=AFAM Shaozhong SHI <<= a href=3D"mailto:shishaozhong@gmail.com">shishaozhong@gmail.com> wro= te:
Given,
ID
5
4
3
3
2
1


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

In Python, there are ways to handl= e ordered list.

In Postgres, is there something si= milar?

ORDER= BY ASC so the "last item" appears first, then "LIMIT 1"= ;

David J.

--000000000000281e4305ffd37dff--