Thanks, Joe and Tom. You cleared the webs out of my brain. I used
HAVING before, but not lately and I got rusty.
Mark
Tom Lane wrote:
Mark Fenbers writes:
I want to do:
SELECT id, count(*) FROM mytable WHERE count(*) > 2 GROUP BY id;
But this doesn't work b
Mark Fenbers writes:
> I want to do:
> SELECT id, count(*) FROM mytable WHERE count(*) > 2 GROUP BY id;
> But this doesn't work because Pg won't allow aggregate functions in a
> where clause.
Use HAVING, not WHERE. The way you are trying to write the query is
meaningless because WHERE filters
Mark,
Change your query to this:
SELECT id, count(*) FROM mytable GROUP BY id HAVING count(*) > 2;
-Original Message-
From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org] On
Behalf Of Mark Fenbers
Sent: Thursday, March 18, 2010 10:07 AM
To: pgsql-sql@postgresql