Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 645CD9FB513 for ; Mon, 16 Jul 2007 08:16:01 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 92086-08 for ; Mon, 16 Jul 2007 08:15:49 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from smadev.internal.net (host3.dynacom.ondsl.gr [62.103.35.211]) by postgresql.org (Postfix) with ESMTP id BE2E79FB4B8 for ; Mon, 16 Jul 2007 08:15:57 -0300 (ADT) Received: from smadev.internal.net (localhost [127.0.0.1]) by smadev.internal.net (8.13.6/8.13.6) with ESMTP id l6GBFjss004077 for ; Mon, 16 Jul 2007 14:15:45 +0300 (EEST) (envelope-from achill@matrix.gatewaynet.com) Received: from localhost (localhost [[UNIX: localhost]]) by smadev.internal.net (8.13.6/8.13.6/Submit) id l6GBFjIk004076 for pgsql-sql@postgresql.org; Mon, 16 Jul 2007 14:15:45 +0300 (EEST) (envelope-from achill@matrix.gatewaynet.com) From: Achilleas Mantzios Organization: Dynacom Tankers Mgmt To: pgsql-sql@postgresql.org Subject: Re: Having the sum of two queries Date: Mon, 16 Jul 2007 14:15:44 +0300 User-Agent: KMail/1.9.3 References: <469B512D.70507@gmail.com> In-Reply-To: <469B512D.70507@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200707161415.45307.achill@matrix.gatewaynet.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/92 X-Sequence-Number: 28827 =CE=A3=CF=84=CE=B9=CF=82 =CE=94=CE=B5=CF=85=CF=84=CE=AD=CF=81=CE=B1 16 =CE= =99=CE=BF=CF=8D=CE=BB=CE=B9=CE=BF=CF=82 2007 14:06, =CE=BF/=CE=B7 Dani Cast= a=C3=B1os =CE=AD=CE=B3=CF=81=CE=B1=CF=88=CE=B5: > Hi all! > > I want to do something like this: > > SELECT status, COUNT( status ) AS total > FROM users > GROUP BY status > > UNION > > SELECT status, COUNT(status) AS total > FROM imported_users > GROUP BY status > > > And have the result of both added. > > I've tried something like > > SELECT tot.status, COUNT(total) > FROM( QUERY A UNION QUERY B ) AS tot > GROUP BY tot.status > > But it doesn't works. It doesn't add the total columns with the same > status... It should also be UNION ALL, just in case some status'es are common in the = 2=20 subqueries. > > ---------------------------(end of broadcast)--------------------------- > TIP 7: You can help support the PostgreSQL project by donating at > > http://www.postgresql.org/about/donate =2D-=20 Achilleas Mantzios