Re: union with count?

From: Andreas Kretschmer <akretschmer(at)spamfence(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: union with count?
Date: 2007-03-28 16:19:06
Message-ID: 20070328161906.GA17735@KanotixBox
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Gerardo Herzig <gherzig(at)fmed(dot)uba(dot)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°

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Ray Madigan 2007-03-28 16:25:17 Rules with sequence columns
Previous Message Tom Lane 2007-03-28 16:17:05 Re: Rules with sequence columns