Re: How to select the last value/row?

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Shaozhong SHI <shishaozhong(at)gmail(dot)com>
Cc: pgsql-sql <pgsql-sql(at)lists(dot)postgresql(dot)org>
Subject: Re: How to select the last value/row?
Date: 2023-07-06 15:51:09
Message-ID: CAKFQuwaS8FX+r3uBpjmS_6EcnOHKbi33thrOBQW_Zd9RLA6nOw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Thu, Jul 6, 2023 at 8:47 AM Shaozhong SHI <shishaozhong(at)gmail(dot)com> 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.

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Shaozhong SHI 2023-07-06 16:02:40 Re: How to select the last value/row?
Previous Message Shaozhong SHI 2023-07-06 15:46:55 How to select the last value/row?