Re: subquery/alias question

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Madison Kelly <linux(at)alteeve(dot)com>
Cc: Michael Glaesemann <grzm(at)seespotcode(dot)net>, PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: subquery/alias question
Date: 2007-09-26 12:55:38
Message-ID: 20070926125538.GF5584@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Madison Kelly wrote:

> Thanks for your reply!
>
> Unfortunately, in both cases I get the error:
>
> nmc=> SELECT dom_id, dom_name, COUNT(usr_dom_id) AS usr_count FROM domains
> JOIN users ON (usr_dom_id=dom_id) HAVING COUNT (usr_dom_id) > 0 ORDER BY
> dom_name;
> ERROR: syntax error at or near "COUNT" at character 25
> LINE 1: SELECT dom_id, dom_name COUNT(usr_dom_id) AS usr_count FROM ...

Try to avoid missing the comma before the COUNT (and do not cheat when
cut'n pasting ...)

Also it seems you will need a GROUP BY clause:
GROUP BY dom_id, dom_name
(placed just before the HAVING clause).

--
Alvaro Herrera http://www.amazon.com/gp/registry/CTMLCN8V17R4
"Some men are heterosexual, and some are bisexual, and some
men don't think about sex at all... they become lawyers" (Woody Allen)

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message manju arumugam 2007-09-26 12:58:09 regds bulk of records
Previous Message Madison Kelly 2007-09-26 12:41:14 Re: subquery/alias question