Refering to lowest record in select subquery

  • Thread starter Thread starter ram
  • Start date Start date
R

ram

HI All,

In the subquery below how would I refer to the lowest 3 orderID?

Thanks in advance for any help

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
 
ORDER BY Dupe.OrderDate DESC, Dupe.OrderID ASC)

You might need to remove " Dupe.OrderDate DESC, " if you are just interested
in the OrderID.
 
Thank you Jerry just what I needed

Jerry Whittle said:
ORDER BY Dupe.OrderDate DESC, Dupe.OrderID ASC)

You might need to remove " Dupe.OrderDate DESC, " if you are just interested
in the OrderID.
 
Back
Top