Re: Selecting latest value

From: Patrik Kudo <kudo(at)partitur(dot)se>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Haller Christoph <ch(at)rodos(dot)fzk(dot)de>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Selecting latest value
Date: 2001-09-20 15:12:42
Message-ID: Pine.BSF.4.31.0109201711020.17720-100000@tb303.partitur.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


On Thu, 20 Sep 2001, Tom Lane wrote:

> This is what SELECT DISTINCT ON was invented for. I don't know any
> comparably easy way to do it in standard SQL, but with DISTINCT ON
> it's not hard:
>
> SELECT DISTINCT ON (userid) userid, val, ts FROM table
> ORDER BY userid, ts DESC;
>
> See the DISTINCT ON example in the SELECT reference page for more info:
> http://www.ca.postgresql.org/users-lounge/docs/7.1/postgres/sql-select.html

Thanks!

I was trying some stuff with distinct on, but in combination with max(ts),
which obviously didn't work. Now it works much better =)

/Patrik Kudo

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Thurstan R. McDougle 2001-09-20 15:23:01 Re: table restruct...
Previous Message Tom Lane 2001-09-20 15:07:35 Re: Selecting latest value