>>I need a query to extract the most recent price inserted for a product
>>i.e.
>>
>>
>>id_product year price
>>1 2004 12004
>>1 2003 12003
>>2 2003 22003
>>2 2002 22002
>>
>>
>>so as to obtain
>>
>>id_product year price
>>1 2004 12004
>>2 2003 22003
>>
>>
>>
>>Which is the SQL syntax to perform the Select?
>>TIA
>
>SELECT TOP 1 price FROM {table} ORDER BY year DESC
Hmmm...that wouldn't work, that would only give you the very first one. You'd need a group by clause to make it work properly. Here's an example using the Northwind.Orders table:
select freight, orderdate from orders
where orderid in
(select min(orderid) from orders
group by datepart(yy,orderdate))
Dan LeClair
www.cyberwombat.comSET RANT ON - The Wombat BlogLife isn’t a morality contest and purity makes a poor shield. - J. Peter MulhernDisclaimer: The comments made here are only my OPINIONS on various aspects of VFP, SQL Server, VS.NET, systems development, or life in general, and my OPINIONS should not be construed to be the authoritative word on any subject. No warranties or degrees of veracity are expressed or implied. Void where prohibited. Side effects may included dizziness, spontaneous combustion, or unexplainable cravings for dark beer. Wash with like colors only, serve immediately for best flavor.