View Full Version : Selecting limited rows


vtrm
10-13-2005, 01:33 AM
I have a table containing items and their prices. I need to run a SELECT Query which can return the last 5 prices for each item.

My Query is:
SELECT item, podate, price
FROM PurchaseOrders
GROUP BY item, podate, price
ORDER BY item, podate DESC, price

Let's say my Item A001 returned 12 records. I need only the 1st 5 records in my Report.

Can anybody help pls???????????

Jeroen
10-14-2005, 03:10 AM
Hi, you can accomplish that by altering your statement to:

SELECT top 5 item, podate, price
FROM PurchaseOrders
GROUP BY item, podate, price
ORDER BY item, podate DESC, price

vtrm
10-15-2005, 05:21 AM
Thanks a bunch, Jeroen. It works perfect.