Search Postgresql Archives

return MAX and when it happened

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

 



Hi all,

suppose I have a table like:

CREATE TABLE mytab
(
    num integer,
    mydate timestamp
);

and I want to find MAX(num) and the "mydate" where it first happened.

I guess I could use

select * from mytab where num = (select MAX(num) from mytab) order by
mydate limit 1;

but that would scan the data twice (I guess...)

Do I have to write my own MAX function, something like:

select MYMAX(num, timestamp) from mytab

which would return a custom type?
Or is there a better way?






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