Re: How to select the last value/row? - Mailing list pgsql-sql

From David G. Johnston
Subject Re: How to select the last value/row?
Date
Msg-id CAKFQuwZuhDQ3GsQLreBB15SvehBRz_iJhFoo-qxgtAgmiEXSOQ@mail.gmail.com
Whole thread Raw
In response to Re: How to select the last value/row?  (Shaozhong SHI <shishaozhong@gmail.com>)
List pgsql-sql
On Thu, Jul 6, 2023 at 9:02 AM Shaozhong SHI <shishaozhong@gmail.com> 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.

pgsql-sql by date:

Previous
From: Shaozhong SHI
Date:
Subject: Re: How to select the last value/row?
Next
From: Tom Lane
Date:
Subject: Re: How to select the last value/row?