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 JAA24444 for ; Tue, 22 Jun 1999 09:05:33 -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 IAA10765; Tue, 22 Jun 1999 08:03:19 -0500 From: Darren Greer Reply-To: dgreer@websightsolutions.com Organization: Websight Solutions To: Tom Lane Subject: Re: [SQL] Trouble with massive select statement. Date: Tue, 22 Jun 1999 07:08:40 -0500 X-Mailer: KMail [version 1.0.21] Content-Type: text/plain Cc: pgsql-sql@postgreSQL.org References: <18337.930007761@sss.pgh.pa.us> MIME-Version: 1.0 Message-Id: <99062207125208.13060@george> Content-Transfer-Encoding: 8bit See below > > 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 > > ) > > ; > > The above doesn't seem to me to do what you claim you want to do --- > it seems to be looking for users who have taken the test *more than > once* in the given interval. That is correct......my mistake :) > Assuming that the code is right and the comment wrong ;-), I agree Good assumption :) > SELECT username, station FROM testmaster > WHERE test_date > '05-14-1999' and station = 'WZZZ' > GROUP BY username, station > HAVING count(*) > 1; This works wonderfully, thanks. Now comes the other twist. I already have a select statement (select first_name, email from listeners l, listeners_data ld where l.username = ld.username a nd $filter;). The $filter is a bunch of and statements that limit the data coming from the table listeners. I need to get the select statement you told me to work as a filter on the data that this select statement grabs. I cant see an easy way to do this without making this thing incredibly slow having to chech every user. Any thoughts? Darren