I need to make a table that includes the top 10 records from another table. I think this analogy describes it quite well.
I have 3 fields in a table;
[SalesPerson] - [OrderNo] - [OrderAmount]
Each sales person has thousands of orders. I want to use a Make Table query that inserts the top 10 (by value) orders for each and every sale person. Its as simple as that!
I want to include all three fields in the new table that will effectively be a subset of records in the first table.
I hope I have made this clear!
Paul
(The inevitable duplicating data arguement).
However it could be for some exporting process or freestyle reporting/alteration of data.
SELECT
T1.[SalesPerson], T1.[OrderNo], T1.[OrderAmount] INTO NewTableName
FROM
tblOrders T1
WHERE T1.[OrderNo] IN
(SELECT TOP 10 [OrderNo]
FROM tblOrders T2
WHERE T1.[SalesPerson] = T2.[SalesPerson]
ORDER BY T2.[OrderAmount] DESC, T1.[OrderNo])
ORDER BY T1.[SalesPerson], T2.[OrderAmount] DESC