Link to home
Create AccountLog in
Avatar of nachtmsk
nachtmskFlag for United States of America

asked on

SQL query using count(*) and GROUP BY

Hi,
I have this query, which works fine:
select count(*) c, CompanyName from Area  GROUP BY CompanyName order by c desc

I want to include a clause that only returns records where c  is > 1.

I tried
select count(*) c, CompanyName from Area  where count(*) > 1 GROUP BY CompanyName order by c desc
But I'm getting an error saying I need to use a Having clause. I tried playing around with that but I haven't gotten it yet.
Can someone help out please?
Thanks,
Nacht
Avatar of tim_cs
tim_cs
Flag of United States of America image

select count(*) c, CompanyName from Area  GROUP BY CompanyName HAVING count(*) > 1
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of nachtmsk

ASKER

Thanks! I actually figured it out 5 mins after I posted, but you still get the points!
Why not at least a points split?  I posted the same thing and first.