Query to see only first several records

  • Thread starter Thread starter Charles W
  • Start date Start date
C

Charles W

I have a customer order table that contains customer names and their orders

Customer Order

A 10
A 9
A 3
B 5
B 10
B 9

Is it possible to set up a query to see only the first 2 top orders of each
customers (or any number of top orders)?

Thanks in advance.

Charles
 
Define "top".

You use a subquery to get the subset of Order values for each customer,
based on what you mean by "top" orders.

For example, assuming that you want "top" to mean the largest numbers for
the Order field:

SELECT CustomerOrder.Customer, CustomerOrder.Order
FROM CustomerOrder
WHERE CustomerOrder.Order IN
(SELECT TOP 2 T.Order
FROM CustomerOrder T
WHERE T.Customer = CustomerOrder.Customer
ORDER BY T.Order DESC);
 
Back
Top