I'm trying to select the 5 rows with the highest count
value
This is my query:
string sql = "SELECT top 5 count FROM Likes ORDER BY COUNT(*) DESC";
It's just throwing an error code that
Column 'Likes.count' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
It's for a project I've got to present tomorrow...
On SQL Server, simply do this:
This assumes that your
Likes
-table already contains a column named[Count]
meaning that you don't need to count the records yourself (which is whatCOUNT(*)
does).