public inbox for [email protected]  
help / color / mirror / Atom feed
From: Tom Lane <[email protected]>
To: Shaozhong SHI <[email protected]>
Cc: David G. Johnston <[email protected]>
Cc: pgsql-sql <[email protected]>
Subject: Re: How to select the last value/row?
Date: Thu, 06 Jul 2023 12:12:01 -0400
Message-ID: <[email protected]> (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>

Shaozhong SHI <[email protected]> writes:
> How about
> ID
> 5
> 4
> 3
> 3
> 2
> 3

> The last is 3.

You need to reorient your thinking.  In SQL, row sets are unordered sets
of values --- this is not a Postgres deficiency, it's a fundamental tenet
of the relational data model.  If you want some kind of ordering, you have
to express that by an ORDER BY clause, which means you need something
within the data that corresponds to what you want the ordering to be.
Your example above is basically nonsense from the standpoint of SQL.

			regards, tom lane






view thread (5+ messages)

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], [email protected]
  Subject: Re: How to select the last value/row?
  In-Reply-To: <[email protected]>

* 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