On Fri, Apr 15, 2005 at 21:58:31 +1000, Alex <alex@xxxxxxxxxxxxxxx> wrote: > Hi, > > i have a table > > ProdId | LastUpdate > -------+------------ > 100 | 2005-04-01 > 100 | 2005-03-01 > 100 | 2005-02-01 > 200 | 2005-04-01 > 200 | 2005-03-01 > 200 | 2005-02-01 > > - How can i select only the newest record for each ProdId ? > > 100 | 2005-04-01 > 200 | 2005-04-01 You can also use the Postgres specific DISTINCT ON clause. SELECT DISTINCT ON (prodid) prodid, lastupdate ORDER BY prodid, lastupdate DESC; ---------------------------(end of broadcast)--------------------------- TIP 9: the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match