Trouble with massive select statement. - Mailing list pgsql-sql

From Darren Greer
Subject Trouble with massive select statement.
Date
Msg-id 99062116013106.13060@george
Whole thread Raw
Responses Re: [SQL] Trouble with massive select statement.
List pgsql-sql
Hello all, first a bit of information.

I have the following tables:
listeners (username text, first_name text, last_name text, email text, station
char(10) );  
listeners_data (username text, signup_date, zip_text text); 
testmaster (username text, test_date date, station char(10) );

Now what I need to do is select all the users who have taken a test (for a
particular station) within, say the last so many number of days.  The following
select statement does that.  However I need the following select statement to
work inside of another select statement.  

select distinct username, station from testmaster t1 where 1 < (    select count(t2.username)         from testmaster
t2       where t2.test_date > '05-14-1999'         and t2.station = 'WZZZ'         and t1.username = t2.username    )
 
;

I already have this select statement:select first_name, email from listeners l, listeners_data ld where l.username =
ld.usernamea
 
nd l.station = 'XXXX';
Now this select statement must only grab data if l.username exists in the data
retrieved from the first select statement I listed.  This seems awefully
convoluded to me, and I expect on a large table, this could take a long time. 
Therefore, I am open to any thoughts on a better way to do this.  Please let me
know if you need any more information and I will be glad to provide it.

Darren






pgsql-sql by date:

Previous
From: Fomichev Michael
Date:
Subject: Re: [BUGS] General Bug Report: CREATE TABLE AS doesn't work
Next
From: Tom Lane
Date:
Subject: Re: [SQL] Trouble with massive select statement.