Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id C48AA9FB94D for ; Wed, 28 Mar 2007 11:27:37 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 27763-02 for ; Wed, 28 Mar 2007 11:27:25 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from web31809.mail.mud.yahoo.com (web31809.mail.mud.yahoo.com [68.142.207.72]) by postgresql.org (Postfix) with SMTP id 254389FBA4B for ; Wed, 28 Mar 2007 11:27:30 -0300 (ADT) Received: (qmail 86224 invoked by uid 60001); 28 Mar 2007 14:27:29 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=Q3GKG5BzDQaxokJN2KpK4kk3MHUm3xY+vRpkXKAQ9bcw1ugsCA9MDY0YvwPffylm3VSU5jbPLDPhZOMmogjEbBEI6XRtGh9f+a9Qe7XbkqFtOz1ZjUNMZRxz8PnRMXe8HrqNQr8rdX5wD89tN0QFphnZejGz2Qa/b9d9wmWtVLY=; X-YMail-OSG: cw7WtyQVM1n9bCUlutqjb0TgFOWJ0Nxf73MN.RpjMeOSVjqotPFdaJ_YTl_WjNjofRWJidgyfZTECG5gZq7_GPSuNywn2g3YnH2s23QA7VkcwPl5r40- Received: from [63.203.180.122] by web31809.mail.mud.yahoo.com via HTTP; Wed, 28 Mar 2007 07:27:29 PDT Date: Wed, 28 Mar 2007 07:27:29 -0700 (PDT) From: Richard Broersma Jr Subject: Re: union with count? To: Gerardo Herzig , pgsql-sql@postgresql.org In-Reply-To: <460A75ED.6070501@fmed.uba.ar> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <437650.83949.qm@web31809.mail.mud.yahoo.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=2.044 tagged_above=0 required=5 tests=AWL=-1.126, BAYES_40=-0.185, DNS_FROM_RFC_ABUSE=0.2, DNS_FROM_RFC_POST=1.708, DNS_FROM_RFC_WHOIS=1.447 X-Spam-Level: ** X-Archive-Number: 200703/333 X-Sequence-Number: 27971 --- Gerardo Herzig wrote: > Hi dudes, i have the following question > i have 2 tables with the same format, and i want to know if is there a > possibility of using some sort of count(*) for achieving this result: > select a from table1 where (condition) union select a from table2 where > (condition), count(a) group by a I think you are showing count(a) in the wrong spot in your example. But if I understand you correctly the following should do what you want: SELECT count(a) FROM ( SELECT a FROM table1 WHERE (your_condition = true) UNION -- you can use UNION ALL if you -- want rows that are duplicates from each table. SELECT a FROM table2 WHERE (your_condition = true) ) GROUP BY a;