nachtmsk
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
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
select count(*) c, CompanyName from Area GROUP BY CompanyName HAVING count(*) > 1
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
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.