PDA

View Full Version : ordering query by COUNT


Bobafart
12-04-2008, 11:23 PM
My table is set up for keywords like this:

id threadid keyWords
1 8507 entertainment
2 8507 theater
3 8507 The
4 8507 First
5 8507 Award
6 8507 Guardian
... etc...
some of these keyWords repeat themselves and I want to query the 10 most frequently appearing keywords

How would I SELECT the top 10 commonly occurring keywords from my table?

SELECT keyWords FROM myTable where COUNT(keyWords) LIMIT 10 doesnt work...

oesxyl
12-04-2008, 11:30 PM
My table is set up for keywords like this:

id threadid keyWords
1 8507 entertainment
2 8507 theater
3 8507 The
4 8507 First
5 8507 Award
6 8507 Guardian
... etc...
some of these keyWords repeat themselves and I want to query the 10 most frequently appearing keywords

How would I SELECT the top 10 commonly occurring keywords from my table?

SELECT keyWords FROM myTable where COUNT(keyWords) LIMIT 10 doesnt work...


SELECT keyWords, count(keyWords) FROM myTable
group by keyWords order by COUNT(keyWords) desc LIMIT 10


best regards