From: Eric L. Blevins <eblevins@insight.rr.com>
To: pgsql-sql@postgresql.org
Subject: Help with SQL
Date: Wed, 16 Oct 2002 14:26:11 -0400
Message-ID: <009c01c27541$83bf46b0$0201a8c0@Gateway> (raw)
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?
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: eblevins@insight.rr.com
Subject: Re: Help with SQL
In-Reply-To: <009c01c27541$83bf46b0$0201a8c0@Gateway>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox