Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

To retrived a unique items only but… 2

Status
Not open for further replies.

Goondu

Technical User
Jan 14, 2004
92
SG
This is a sample of a Table called ‘StockItem’

ItemNum UnitPrice SupplyDate
0001 5.00 12-Dec-2007
0001 12.00 10-Jul-2007
0002 7.00 12-Dec-2007
0003 2.00 12-Dec-2007
0004 3.00 12-Dec-2007
0004 5.00 10-Jul-2007

I need to retrieve the rows of ItemNum base on the last ‘SupplyDate’. I am having problems excluding rows with the same ‘ItemNum’, example.

ItemNum UnitPrice SupplyDate
0001 12.00 10-Jul-2007
0002 7.00 12-Dec-2007
0003 2.00 12-Dec-2007
0004 5.00 10-Jul-2007

Due to the UnitPrice difference, I need to pick only one from the ItemNum base on the SupplyDate.

Anyone can help? Version 2000.

Thanks.
 
Another way:
SELECT A.*
FROM StockItem INNER JOIN (
SELECT ItemNum, Max(SupplyDate) AS LastDate FROM StockItem GROUP BY ItemNum
) AS B ON A.ItemNum = B.ItemNum AND A.SupplyDate = B.LastDate

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you, Duane

It works. Had to use the Min() function to retrive older records.

Thank you, PHV

Had to edit a little to get it right.

SELECT A.*
FROM StockItem A INNER JOIN (
SELECT ItemNum, Min(SupplyDate) AS LastDate FROM StockItem B GROUP BY ItemNum
) AS B ON A.ItemNum = B.ItemNum AND A.SupplyDate = B.LastDate;

Thanks for helping me to get around this problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top