Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 2E7F79FB79A for ; Mon, 16 Jul 2007 19:01:05 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 53165-08 for ; Mon, 16 Jul 2007 19:00:51 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from sapo.pt (relay1.ptmail.sapo.pt [212.55.154.21]) by postgresql.org (Postfix) with SMTP id 5A9619FB893 for ; Mon, 16 Jul 2007 19:01:01 -0300 (ADT) Received: (qmail 32388 invoked from network); 16 Jul 2007 22:00:48 -0000 Received: from unknown (HELO sapo.pt) (10.134.35.159) by relay1 with SMTP; 16 Jul 2007 22:00:48 -0000 Received: (qmail 333 invoked from network); 16 Jul 2007 22:00:48 -0000 X-AntiVirus: PTMail-AV 0.3-0.90.3 X-Virus-Status: Clean (0.01868 seconds) Received: from unknown (HELO hmv02) (hmv@[82.155.149.166]) (envelope-sender ) by mta9 (qmail-ldap-1.03) with SMTP for ; 16 Jul 2007 22:00:48 -0000 Message-ID: <001401c7c7f4$c4515280$6200a8c0@hmv02> From: =?iso-8859-1?Q?H=E9lder_M._Vieira?= To: References: <469B512D.70507@gmail.com> Subject: Re: Having the sum of two queries Date: Mon, 16 Jul 2007 23:00:47 +0100 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=response Content-Transfer-Encoding: 8bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.3138 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.085 tagged_above=0 required=5 tests=AWL=0.084, BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 200707/95 X-Sequence-Number: 28830 >... 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... >... I guess you have two problems, if I understand what you're trying to do. - As Roberto Spier noted, 'sum' would be better than 'count' in the outer query. - Also, 'union' will silently remove duplicate rows, unless you use 'union all'. Please check if this is what you want: select status, count(status) from ( select status from users union all select status from imported_users ) as fff group by status; Regards, ´ Helder M. Vieira