Skip site navigation (1) Skip section navigation (2)

need some more select help

From: A B <gentosaker(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: need some more select help
Date: 2009-07-17 08:23:28
Message-ID: dbbf25900907170123n5e1e5706ga5324ec5eb77d65c@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
I'm trying to

select a,count(1) FROM (select a from X UNION select a from Y ) group by a;

but it complains and says that the subquery must have an alias and I
have not figured it out how to add that.

Btw. is there any other way of doing what I'm doing above?

It's basically    select a,count(1) from X group by a     +  select
a,count(1) from Y  group by a  where  "+" means they should be summed
on the "a" field.

I tried
select a,sum(b)   from ( select a,count(1) as b from X group by a
union select a,count(1) as b from Y group by a) group by a

but that gave also an error asking for an alias for the subquery.

How can I solv this problem?

Responses

pgsql-novice by date

Next:From: tharaDate: 2009-07-17 08:34:24
Subject: Re: need some more select help
Previous:From: Emil ObermayrDate: 2009-07-16 10:42:12
Subject: Re: SELECT DISTINCT and count(1)

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group