X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.192]) by svr1.postgresql.org (Postfix) with ESMTP id 06D08CC5EA for ; Wed, 16 Jul 2003 20:52:37 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr4.postgresql.org [64.117.224.192]) (amavisd-new, port 10024) with ESMTP id 05284-01 for ; Wed, 16 Jul 2003 20:53:00 +0000 (GMT) Received: from mail.securitylending.com (cust-66-182-85-69.connectbbs.com [66.182.85.69]) by svr1.postgresql.org (Postfix) with ESMTP id 6945ECADB6 for ; Wed, 16 Jul 2003 17:52:34 -0300 (ADT) Subject: Why do the two queries below return different results? From: Warren Little To: pgsql-sql@postgresql.org Content-Type: text/plain Content-Transfer-Encoding: 7bit Message-Id: <1058388773.5345.8.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.3 Date: 16 Jul 2003 14:52:53 -0600 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/285 X-Sequence-Number: 14399 Look at the following two queries. select casepid, origpid from virbcase where date_trunc('day', origdt) >= '2003-07-01' and date_trunc('day', origdt) <= '2003-07-31' and origpid in (select pid from party where partyid in ('00339', '00310', '00320')) and not exists (select pid from casecombo where casepid = secondpid) select casepid, origpid from virbcase where date_trunc('day', origdt) >= '2003-07-01' and date_trunc('day', origdt) <= '2003-07-31' and origpid in (select pid from party where partyid in ('00339', '00310', '00320')) and casepid not in (select secondpid from casecombo) The second query is broken and I don't understand why. Correlating the subquery as is done in the first query fixes it. -- Warren Little Senior Vice President Secondary Marketing Security Lending Wholesale, LC www.securitylending.com Tel: 866-369-7763 Fax: 866-849-8082