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 in Others by nisha
• 2,160 points
5 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 in Others by Sohail
• 2,960 points
10 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 in Others by nisha
• 2,160 points
16 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 in Others by nisha
• 2,160 points
13 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,340 points
316 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,720 points
759 views
0 votes
1 answer
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 in Others by Edureka
• 13,640 points
43 views
0 votes
0 answers

Two Backslash in SQL procedure with regular expression

On SQL procedure where i saw a Regular ...READ MORE

May 26 in Others by polo
• 1,500 points
17 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP