Forum Discussion

GarthVader's avatar
GarthVader
Copper Contributor
Feb 22, 2024

How to get the top occurrence of rows to show SSMS 19

I am struggling to get the most occurring rows to show in SSMS 19.

ChatGPT gave me:

SELECT TOP 1 Product, COUNT(*) AS Occurrences

FROM Sales

WHERE Product IS NOT NULL

GROUP BY Product

ORDER BY Occurrences DESC;

 

This code runs but gives the incorrect results, I know by a manual filter in Excel that the results are wrong. 

Does anyone know what could be wrong?

Resources