Re: union with count? - Mailing list pgsql-sql

From A. Kretschmer
Subject Re: union with count?
Date
Msg-id 20070328142444.GA20168@a-kretschmer.de
Whole thread Raw
In response to union with count?  (Gerardo Herzig <gherzig@fmed.uba.ar>)
Responses Re: union with count?
List pgsql-sql
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


pgsql-sql by date:

Previous
From: Gerardo Herzig
Date:
Subject: union with count?
Next
From: Richard Broersma Jr
Date:
Subject: Re: union with count?