I am trying to build a query that displays the rows with the highest values in the aggregate column, “NumberOfArticles”. However, since there are multiple rows with the same highest value, I am unsure how to properly limit the number of rows generated by the query.
SELECT WRT_ID, COUNT(ART_ID) AS NumberOfArticles
FROM Articles
GROUP BY WRT_ID
ORDER BY NumberOfArticles DESC
If there are multiple rows with the highest NumberOfArticles count, the ties will be included. If you don’t want the ties included, but only one of those with the highest NumberOfArticles count, put the GROUP BY in a subquery and change the ORDER BY as needed.