Received: from bilbo.websightsolutions.com (dial200-7.mixcom.com [207.250.200.7] (may be forged)) by hub.org (8.9.3/8.9.3) with ESMTP id RAA27856 for ; Mon, 21 Jun 1999 17:52:43 -0400 (EDT) (envelope-from dgreer@websightsolutions.com) Received: from george (root@george.websightsolutions.com [207.250.200.13]) by bilbo.websightsolutions.com (8.9.3/8.9.3/Debian/GNU) with SMTP id QAA07735 for ; Mon, 21 Jun 1999 16:51:46 -0500 From: Darren Greer Reply-To: dgreer@websightsolutions.com Organization: Websight Solutions To: pgsql-sql@postgreSQL.org Subject: Trouble with massive select statement. Date: Mon, 21 Jun 1999 15:45:38 -0500 X-Mailer: KMail [version 1.0.21] Content-Type: text/plain MIME-Version: 1.0 Message-Id: <99062116013106.13060@george> Content-Transfer-Encoding: 8bit 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.username a 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