Help with SQL - Mailing list pgsql-sql

From Eric L. Blevins
Subject Help with SQL
Date
Msg-id 009c01c27541$83bf46b0$0201a8c0@Gateway
Whole thread Raw
Responses Re: Help with SQL
List pgsql-sql
I'm new to postgres.
I've got 2 SQL statements I would like to combine into one.
 
I think I need to use a sub select or join I am not sure.
Any help would be appreciated!
 
statement 1: SELECT  uid, count(uid)  FROM triangulated WHERE uid != 'anonymus' AND uid
!= 'anonymous' AND uid != '' GROUP BY uid ORDER BY count DESC LIMIT 10;

that returns something like this:
 
    uid     | count
-------------+-------
 eblevins    |  1179
 DaClyde     |   398
 Drew        |    30
 zombiechick |     3
(4 rows)

statement 2: SELECT  uid, count(uid)  FROM points WHERE uid != 'anonymus' AND uid !=
'anonymous' AND uid != '' GROUP BY uid ORDER BY count DESC LIMIT 10;
that returns something like this:
     uid     | count
-------------+-------
 eblevins    | 23595
 DaClyde     | 11031
 zombiechick |   159
 Drew        |   104
(4 rows)
 
 
what I want to do is have one statement that returns something like this:
uid    |    count1    | count2
eblevins    1179    23595
DaClyde    398    11031
Drew    30    104
zombiechick    3    159
 
So everything is ordered like statement 1 but includes the count(uid) from the points DB like statement 2 returns
 
Any ideas on an effecient way of doing this?
 
 
 

pgsql-sql by date:

Previous
From: Vincent Stoessel
Date:
Subject: Quick contraint question
Next
From: Oliver Elphick
Date:
Subject: Re: Help with SQL