SQL Group By with an Order By

0 votes

I have a table of tags and want to get the highest count tags from the list.

Sample data looks like this

id (1) tag ('night')
id (2) tag ('awesome')
id (3) tag ('night')

using

SELECT COUNT(*), `Tag` from `images-tags`
GROUP BY `Tag`

gets me back the data I'm looking for perfectly. However, I would like to organize it, so that the highest tag counts are first, and limit it to only send me the first 20 or so.

I tried this...

SELECT COUNT(id), `Tag` from `images-tags`
GROUP BY `Tag`
ORDER BY COUNT(id) DESC
LIMIT 20

and I keep getting an "Invalid use of group function - ErrNr 1111"

What am I doing wrong?

Jun 22, 2022 in Others by nisha
• 2,210 points
406 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Others

0 votes
1 answer

Ordering by the order of values in a SQL IN() clause

We can use expressions as well in ...READ MORE

answered May 31, 2022 in Others by Sohail
• 3,040 points
653 views
0 votes
1 answer

Ordering by the order of values in a SQL IN() clause

Use MySQL FIND_IN_SET function: SELECT * ...READ MORE

answered Jun 6, 2022 in Others by nisha
• 2,210 points
674 views
0 votes
1 answer

SQL Server: Difference between PARTITION BY and GROUP BY

We can take a simple example. Consider a ...READ MORE

answered Jun 21, 2022 in Others by nisha
• 2,210 points
1,101 views
0 votes
1 answer

VBA - Build an Array by Looping Through Another Array with Specific Criteria

Please attempt the next option. It is ...READ MORE

answered Mar 23, 2023 in Others by narikkadan
• 63,600 points
600 views
0 votes
1 answer

In order to learn Node.js, I should be familiar with which other technologies ?

I appreciate your decision, its the perfect ...READ MORE

answered Jul 31, 2019 in Others by ArchanaNagur
• 2,360 points
870 views
0 votes
1 answer

I am trying to run following command But I end up with an error :

Hii Nishant, You are running this command inside ...READ MORE

answered Apr 6, 2020 in Others by Niroj
• 82,840 points
1,856 views
0 votes
1 answer
0 votes
1 answer

"The underlying connection was closed: An unexpected error occurred on a send." With SSL Certificate

The solution for this for me was ...READ MORE

answered Feb 18, 2022 in Others by Rahul
• 9,680 points
11,404 views
0 votes
1 answer
0 votes
1 answer

Refresh powerbi online with SQL data base (RDS AWS)

It must connect to the database successfully ...READ MORE

answered Mar 25, 2022 in Others by Edureka
• 13,690 points
1,194 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP