Refering to lowest record in select subquery

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
 
J

Jerry Whittle

ORDER BY Dupe.OrderDate DESC, Dupe.OrderID ASC)

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

ram

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top