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 08:51:09 -0700
Message-ID: <CAKFQuwaS8FX+r3uBpjmS_6EcnOHKbi33thrOBQW_Zd9RLA6nOw@mail.gmail.com> (raw)
In-Reply-To: <CA+i5JwZj2iCWVok4Bh7E3Z1tWtXrU0ipyPZ0810gkPso7fKRuA@mail.gmail.com>
References: <CA+i5JwZj2iCWVok4Bh7E3Z1tWtXrU0ipyPZ0810gkPso7fKRuA@mail.gmail.com>

On Thu, Jul 6, 2023 at 8:47 AM Shaozhong SHI <[email protected]> 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.


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: <CAKFQuwaS8FX+r3uBpjmS_6EcnOHKbi33thrOBQW_Zd9RLA6nOw@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