Hi, I have a database of products, orders and order details. I am trying to write a query that returns the most recent unit prices.
This means that I need to see each item that has been sold, and it's most recent price sold. This is what I wrote so far:
But I'm getting many dates, and not just the most recent ones. Does anyone know what I am doing wrong? I am using SQL Server 2000.
Thank you,
Nader
This means that I need to see each item that has been sold, and it's most recent price sold. This is what I wrote so far:
Code:
SELECT ItemNumber, Max(ClientOrderDate), UnitPrice
FROM (Orders
RIGHT JOIN OrderDetails ON Orders.OrderNumber = OrderDetails.OrderHeaderNumber)
WHERE OrderType LIKE '%STANDARD%' AND CustomerCode LIKE 'COST%'
GROUP BY ItemNumber, ClientOrderDate, UnitPrice
HAVING ClientOrderDate = MAX(ClientOrderDate)
ORDER BY ItemNumber
Thank you,
Nader