Re: union with count?

From: Gerardo Herzig <gherzig(at)fmed(dot)uba(dot)ar>
To: pgsql-sql(at)postgresql(dot)org
Cc: andreas(dot)kretschmer(at)schollglas(dot)com
Subject: Re: union with count?
Date: 2007-03-28 15:23:17
Message-ID: 460A8865.3070005@fmed.uba.ar
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Thanks! But now i have another problem related with count():

select page_id, word, word_position, count(page_id) from (select * from
search_word('word1', 'table1') union search_word('word2', 'table2')) foo
group by page_id;

and gives me "foo.word must appear in GROUP clause or be used in an
aggregate function"

And i want to group by page_id only, because that is what i need to
count. Tips here?

Thanks again man.
Gerardo

>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
>
>

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2007-03-28 16:17:05 Re: Rules with sequence columns
Previous Message Richard Broersma Jr 2007-03-28 14:27:29 Re: union with count?