public inbox for [email protected]  
help / color / mirror / Atom feed
From: David G. Johnston <[email protected]>
To: Shaozhong SHI <[email protected]>
Cc: pgsql-sql <[email protected]>
Subject: Re: How to select the last value/row?
Date: Thu, 6 Jul 2023 09:09:36 -0700
Message-ID: <CAKFQuwZuhDQ3GsQLreBB15SvehBRz_iJhFoo-qxgtAgmiEXSOQ@mail.gmail.com> (raw)
In-Reply-To: <CA+i5Jwb2qqUKnPvVHwA8W6HG7AZdCFgu4BajrJpivaTSSxyXqQ@mail.gmail.com>
References: <CA+i5JwZj2iCWVok4Bh7E3Z1tWtXrU0ipyPZ0810gkPso7fKRuA@mail.gmail.com>
	<CAKFQuwaS8FX+r3uBpjmS_6EcnOHKbi33thrOBQW_Zd9RLA6nOw@mail.gmail.com>
	<CA+i5Jwb2qqUKnPvVHwA8W6HG7AZdCFgu4BajrJpivaTSSxyXqQ@mail.gmail.com>

On Thu, Jul 6, 2023 at 9:02 AM Shaozhong SHI <[email protected]> wrote:

>
> How about
> ID
> 5
> 4
> 3
> 3
> 2
> 3
>
> The last is 3.
>
>
There is no concept of "last" in a query unless you define an order.  If
you really want whatever row really happens to randomly show up in the last
result row the use the "row_number()" window function to give each row a
number and then sort and limit on that.

David J.


view thread (5+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: How to select the last value/row?
  In-Reply-To: <CAKFQuwZuhDQ3GsQLreBB15SvehBRz_iJhFoo-qxgtAgmiEXSOQ@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox