Great. Thanks for the query and the details.
SELECT TblCust.CustID, TblCust.CustName, TblOrder.OrderAmount,
TblOrder.OrderId
FROM TblCust INNER JOIN TblOrder ON TblCust.CustID = TblOrder.CustId
WHERE tblOrder.OrderID IN
(SELECT TOP 3 Dupe.CustID
FROM tblOrder as Dupe
WHERE Dupe.CustID = tblOrder.CustID
ORDER BY Dupe.OrderAmount Desc)
If you want to limit the returns to exactly three records then you may need to
add one more bit to the ORDER BY in the subquery. Right now ties can return
more than three records for any one customer. Let's say that customer 22 has
the following orders and amounts.
22 $100
28 $99
31 $98
27 $98
84 $72
The query would return 22,28, 27, and 31 (because there is a tie for third
place). If all the values in the example were $100, then all five would be returned.
You can limit it to exactly 3 by including the primary key field (orderID) in
the Order by clause
SELECT TblCust.CustID, TblCust.CustName, TblOrder.OrderAmount,
TblOrder.OrderId
FROM TblCust INNER JOIN TblOrder ON TblCust.CustID = TblOrder.CustId
WHERE tblOrder.OrderID IN
(SELECT TOP 3 Dupe.CustID
FROM tblOrder as Dupe
WHERE Dupe.CustID = tblOrder.CustID
ORDER BY Dupe.OrderAmount Desc, Dupe.OrderID)