using max() aggregate - Mailing list pgsql-general

From Louis-David Mitterrand
Subject using max() aggregate
Date
Msg-id 20000616075015.A1105@styx
Whole thread Raw
Responses Re: using max() aggregate  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Hello,

I am trying to return the most recently updated record from a table:

SELECT max(stopdate) FROM auction;

and this works but only returns the timestamp, however if I try to get
another column with the aggregate it fails:

SELECT title,max(stopdate) FROM auction;
ERROR:  Attribute auction.title must be GROUPed or used in an aggregate function

Ok, so I group it now:

SELECT title,max(stopdate) FROM auction GROUP BY title;
     title     |          max
---------------+------------------------
 dfsdfsdf      | 2000-07-10 05:00:00+02
 dssdfsdfsdfsf | 2000-07-09 16:00:00+02
 sdfsdfsdfsdf  | 2001-04-10 15:00:00+02
(3 rows)

But the problem is that I now get three rows when I only want the max()
item.

How should I do it?

Thanks in advance,

--
Louis-David Mitterrand - ldm@apartia.org - http://www.apartia.fr

"Logiciels libres : nourris au code source sans farine animale."

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: coalesce view error
Next
From: Tom Lane
Date:
Subject: Re: using max() aggregate