Re: How to select the last value/row?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Shaozhong SHI <shishaozhong(at)gmail(dot)com>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, pgsql-sql <pgsql-sql(at)lists(dot)postgresql(dot)org>
Subject: Re: How to select the last value/row?
Date: 2023-07-06 16:12:01
Message-ID: 1218123.1688659921@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Shaozhong SHI <shishaozhong(at)gmail(dot)com> 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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Shaozhong SHI 2023-07-06 21:47:12 How do Exception, do nothing and carry on
Previous Message David G. Johnston 2023-07-06 16:09:36 Re: How to select the last value/row?