Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id B53459FB707 for ; Wed, 28 Mar 2007 11:24:57 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 45778-06 for ; Wed, 28 Mar 2007 11:24:41 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.177]) by postgresql.org (Postfix) with ESMTP id F03A99FB979 for ; Wed, 28 Mar 2007 11:24:46 -0300 (ADT) Received: from [194.25.154.138] (helo=webserv.wug.de) by mrelayeu.kundenserver.de (node=mrelayeu8) with ESMTP (Nemesis), id 0ML31I-1HWZ4u42fF-00076T; Wed, 28 Mar 2007 16:24:45 +0200 Received: from kretschmer by webserv.wug.de with local (Exim 3.36 #1) id 1HWZ4u-0005jo-00 for pgsql-sql@postgresql.org; Wed, 28 Mar 2007 16:24:44 +0200 Date: Wed, 28 Mar 2007 16:24:44 +0200 From: "A. Kretschmer" To: pgsql-sql@postgresql.org Subject: Re: union with count? Message-ID: <20070328142444.GA20168@a-kretschmer.de> References: <460A75ED.6070501@fmed.uba.ar> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <460A75ED.6070501@fmed.uba.ar> X-OS: Debian/GNU Linux - weil ich es mir Wert bin! X-Message-Flag: "Windows" is not the answer. "Windows" is the question and the answer is "no"! User-Agent: Mutt/1.5.9i X-Provags-ID: V01U2FsdGVkX18Rc7KxER/NPtOD5UrmSclmfTk0TxAay4xBoLJ RxLyt/ESz+rcnkeflKBZEBemPASSgK2tflsErUD1jYhw/kBGkv fF8fl4Au+xwIB6BV2RzK36U8P2SL5Vp X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200703/332 X-Sequence-Number: 27970 am Wed, dem 28.03.2007, um 11:04:29 -0300 mailte Gerardo Herzig folgendes: > 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 > > The idea is having how many times (condition) is true for both tables. > > Im not shure im explaining myself clearly, my english is not the best > (as you can see ;) You can use a subselect, a simple example: test=# select *, count(1) from (select 1 union select 2 union select 3) foo group by 1; ?column? | count ----------+------- 1 | 1 2 | 1 3 | 1 (3 rows) Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net