Reputation: 21
SELECT t1.CompanyName, COUNT(*) AS TotalOrder
FROM [table1] t1
INNER JOIN [table2] t2 ON t1.CompanyID = t2.CompanyID
GROUP BY t1.CompanyID
ORDER BY COUNT(*) DESC
I have the above code already just that wish to display the most count To the top and less count at the bottom in the gridview how can I do this?
Upvotes: 1
Views: 55
Reputation: 2788
Try This query.
SELECT t1.CompanyName, COUNT(t2.CompanyID) AS TotalOrder
FROM table1 t1 INNER JOIN table2 t2
ON t1.CompanyID = t2.CompanyID
GROUP BY t1.CompanyName
ORDER BY TotalOrder DESC
Upvotes: 2
Reputation: 5077
As far as i understand your question is you want the Company Names listed with row number in descending order. if so try this
SELECT t1.CompanyName, ROW_NUMBER() over (order by CompanyName) AS TotalOrder
FROM table1 t1 INNER JOIN table2 t2
ON t1.CompanyID = t2.CompanyID order by CompanyName desc
Upvotes: 1