views:

58

answers:

1

I have a grouped query, and would like to filter it based on count(*)

Can I do this without a subquery?

This is what I have currently:

select * 
  from (select ID,
               count(*) cnt
          from name
      group by ID)
 where cnt > 1;
+8  A: 

what you are looking for is the HAVING clause:

select ID, count(*) cnt
from name
group by ID
having count(*) > 1;
Eric Petroelje
+1: You were first...
OMG Ponies
But if it came down to picking two identical answers entered at the same time, I think I'd go with Ponies over some guy named Eric :)
chris
@chris - ponies are nice n all, but can you really trust a unicorn with a rainbow coming out of its ass? I think not :)
Eric Petroelje
Good point, but I'm sure you'd get an argument on that point from my daughter :)
chris