MySQL - Using COUNT(*) in the WHERE clause

Ice picture Ice · Nov 19, 2008 · Viewed 277.7k times · Source

I am trying to accomplish the following in MySQL (see pseudo code)

SELECT DISTINCT gid
FROM `gd`
WHERE COUNT(*) > 10
ORDER BY lastupdated DESC

Is there a way to do this without using a (SELECT...) in the WHERE clause because that would seem like a waste of resources.

Answer

Ali Ersöz picture Ali Ersöz · Nov 19, 2008

try this;

select gid
from `gd`
group by gid 
having count(*) > 10
order by lastupdated desc