Search Postgresql Archives

Re: Three fields table: id-data-date_time, how to get max() and date_time same time?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Nov 06, 2009 at 02:09:03PM +1100, Chris wrote:
> select max(data), id, (select max(date_time) from test where id=t1.id) 
> from test t1 group by id;

I'd tend to use the DISTINCT ON[1] operator for these sorts of problems:

  SELECT DISTINCT ON (id) *
  FROM test
  ORDER BY id, data DESC;

-- 
  Sam  http://samason.me.uk/

 [1] http://www.postgresql.org/docs/current/static/sql-select.html#SQL-DISTINCT

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux