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

On Thu, 6 Jul 2023 at 16:51, David G. Johnston <[email protected]>
wrote:

> 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.
>


How about
ID
5
4
3
3
2
3

The last is 3.

Regards,

David


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: <CA+i5Jwb2qqUKnPvVHwA8W6HG7AZdCFgu4BajrJpivaTSSxyXqQ@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