Hi
I am trying to get the last date a Product as been delivered. I have the code like this but this returns all 134 times it as been delivered. I have used a specific Product code to limit the return of rows. I am expecting just the latest date back. I have a feeling I may need a sub query but no idea how to achieve this. Could someone please advise or assist. Thanks
I am trying to get the last date a Product as been delivered. I have the code like this but this returns all 134 times it as been delivered. I have used a specific Product code to limit the return of rows. I am expecting just the latest date back. I have a feeling I may need a sub query but no idea how to achieve this. Could someone please advise or assist. Thanks
SQL:
SELECT dbo.Product.ProductID, dbo.Product.ProductCode, MAX(dbo.JourneyHeader.JourneyDate) AS DelDate, dbo.JourneyHeader.JourneyNumber
FROM dbo.OrderLine INNER JOIN
dbo.Product ON dbo.OrderLine.ProductID = dbo.Product.ProductID INNER JOIN
dbo.JourneyLine INNER JOIN
dbo.JourneyHeader ON dbo.JourneyLine.JourneyID = dbo.JourneyHeader.JourneyID ON dbo.OrderLine.OrderID = dbo.JourneyLine.OrderID
GROUP BY dbo.Product.ProductID, dbo.Product.ProductCode, dbo.JourneyHeader.JourneyNumber
HAVING dbo.Product.ProductCode = 'AM015044CR'