Re: combining two queries?

From: Duane Lee - EGOVX <DLee(at)mail(dot)maricopa(dot)gov>
To: "'Mark Harrison'" <mh(at)pixar(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: combining two queries?
Date: 2004-10-23 00:26:48
Message-ID: 2173F8FD02F0A443BF578E975AF3C793195BBA@EVS2.enterprise.maricopa.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Try

select a.name,count(*) from
xenons as a,
viewer_movies as b
where a.id = b.viewerid
group by a.name order by a.name;

-----Original Message-----
From: Mark Harrison [mailto:mh(at)pixar(dot)com]
Sent: Friday, October 22, 2004 4:55 PM
To: pgsql-general(at)postgresql(dot)org
Subject: [GENERAL] combining two queries?

How can I combine these two queries?

# select viewerid,count(*) from viewer_movies group by viewerid order by
viewerid;
viewerid | count
----------+--------
22964835 | 3055
22964836 | 1291
22964837 | 3105
22964838 | 199

planb=# select name from xenons where id = 23500637;
name
---------
x.moray

I would like to end up with a query result like this:

viewer | count
----------+--------
x.surf | 3055
x.dream | 1291
x.moray | 3105
x.sleepy | 199

Many TIA!
Mark

--
Mark Harrison
Pixar Animation Studios

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Browse pgsql-general by date

  From Date Subject
Next Message Ed L. 2004-10-23 00:37:23 Re: ia64 hostname lookup problem
Previous Message Tom Lane 2004-10-23 00:08:44 Re: Problem with query plan