By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,834 Members | 2,240 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,834 IT Pros & Developers. It's quick & easy.

combining two queries?

P: n/a
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

Nov 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
select b.name as viewer, count(*)
from viewer_movies a, xenons b
where b.id = a.viewerid
group by b.name
On Sat, 2004-10-23 at 00:55, Mark Harrison wrote:
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

--
Edward A. Macnaghten
http://www.edlsystems.com
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 23 '05 #2

P: n/a
If you want to return rows with zeros, you may need to do something like
this:

select b.name as viewer, count(viewerid)
from xenons b left join viewer_movies a on (b.id = a.viewerid)
group by b.name

Eddy Macnaghten wrote:
select b.name as viewer, count(*)
from viewer_movies a, xenons b
where b.id = a.viewerid
group by b.name
On Sat, 2004-10-23 at 00:55, Mark Harrison wrote:

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

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.