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

From Andreas Kretschmer
Subject Re: union with count?
Date
Msg-id 20070328161906.GA17735@KanotixBox
Whole thread Raw
In response to Re: union with count?  (Gerardo Herzig <gherzig@fmed.uba.ar>)
List pgsql-sql
Gerardo Herzig <gherzig@fmed.uba.ar> schrieb:

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

You can't aggregate without grouping the not-aggregated columns.
Expand your 'group by' with word and word_position.


Andreas
-- 
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."    (unknow)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: Rules with sequence columns
Next
From: "Wilkinson, Jim"
Date:
Subject: How too select different views using a IF/THEN/ELSE procedure ?