Re: [SQL] selecting latest record

2009-09-22 Thread Rob Sargent
Let's say there's an index on the date column: Does the where clause approach necessarily out perform the distinct on version? Hoping the OP has enough data to make analyse useful. A. Kretschmer wrote: In response to Louis-David Mitterrand : Hi, I have a simple table price(id_product, p

Re: [SQL] selecting latest record

2009-09-22 Thread A. Kretschmer
In response to Louis-David Mitterrand : > Hi, > > I have a simple table > > price(id_product, price, date) > > which records price changes for each id_product. Each time a price > changes a new tuple is created. > > What is the best way to select only the latest price of each id_product? The

Re: [SQL] selecting latest record

2009-09-22 Thread Louis-David Mitterrand
On Tue, Sep 22, 2009 at 11:56:54AM +0200, Pavel Stehule wrote: > > there are more ways - depends on what you wont. > > one way is > > SELECT * >FROM price > WHERE (id_product, date) = (SELECT id_product, max(date) >FROM price

Re: [SQL] selecting latest record

2009-09-22 Thread Pavel Stehule
Hello 2009/9/22 Louis-David Mitterrand : > Hi, > > I have a simple table > > price(id_product, price, date) > > which records price changes for each id_product. Each time a price > changes a new tuple is created. > > What is the best way to select only the latest price of each id_product? there a

[SQL] selecting latest record

2009-09-22 Thread Louis-David Mitterrand
Hi, I have a simple table price(id_product, price, date) which records price changes for each id_product. Each time a price changes a new tuple is created. What is the best way to select only the latest price of each id_product? Thanks, -- Sent via pgsql-sql mailing list (pgsql-sql@postgre