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.
i think you can not add
count()
withwhere
. now see why ....where
is not same ashaving
,having
means you are working or dealing with group and same work of count , it is also dealing with the whole group ,now how count it is working as whole group
create a table and enter some id's and then use:
you will find the total values means it is indicating some group ! so
where
does added withcount()
;There can't be aggregate functions (Ex. COUNT, MAX, etc.) in A WHERE clause. Hence we use the HAVING clause instead. Therefore the whole query would be similar to this:
try this;
Just academic version without having clause:
EDIT (if you just want the gids):