So I've been trying to get this to work with my specific database, and I just can't wrap my head around it for some reason. My brain gets lost in the subquery. Maybe because I'm working with 2 tables and a query and the code gets confusing. Anyway, from the site you linked to:
Code:
SELECT Orders.CustomerID, Orders.OrderDate, Orders.OrderID
FROM Orders
WHERE Orders.OrderID IN
(SELECT TOP 3 OrderID
FROM Orders AS Dupe
WHERE Dupe.CustomerID = Orders.CustomerID
ORDER BY Dupe.OrderDate DESC, Dupe.OrderID DESC)
ORDER BY Orders.CustomerID, Orders.OrderDate, Orders.OrderID;
I don't understand
Code:
WHERE Dupe.CustomerID = Orders.CustomerID
It's like saying where 1 = 1, so why bother? Or why not use any field from the table since they will all be equal?
It seems like it could just be SELECT TOP 3 FROM <the whole table sorted by date>.