I want to grab Top 10 most Ordered product by customer…
Im counting how many lines that this product have been ordered .
Sample data:
ProdName
A
B
C
A
B
Count A=2 ,B=2,C=1
Here’s my code
SELECT TOP 10 ProdName,COUNT(*) AS OrderCount
FROM SampleTable
GROUP BY ProdName
ORDER BY OrderCount,ProdName
Ive done this in other database using LIMIT 10..
but here in SQL server the result of that query is the bottom record’s
If you want the highest values first, use a DESC sort: