Ian Barwick <[EMAIL PROTECTED]> writes:
> On Sat, 30 Oct 2004 15:17:16 -0700, Shane Wegner
> <[EMAIL PROTECTED]> wrote:
>> Under MySQL, this query does the trick.
>> select lastname,count(*) as c from names group by lastname
>> having c > 1;
>> 
>> Is it possible to do a query like this with PostgreSQL?

> select lastname,count(*) as c from names group by lastname having count(*) > 1;

Just to expand on that: MySQL's abbrevation is not legal SQL, and it's
not even very sensible, because logically speaking the SELECT output
list is only evaluated after (and if) the HAVING clause succeeds.
So it makes no sense for the HAVING clause to refer to SELECT values.

Postgres does optimize the case of multiple identical aggregate-function
invocations in a query, BTW, so the apparent inefficiency is not real.

                        regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
      subscribe-nomail command to [EMAIL PROTECTED] so that your
      message can get through to the mailing list cleanly

Reply via email to