X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 70E89D1C510 for ; Thu, 14 Aug 2003 03:12:36 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 32104-06 for ; Thu, 14 Aug 2003 00:10:57 -0300 (ADT) Received: from megazone.bigpanda.com (45.mufb.snfc.sffca01r18.dsl.att.net [12.103.249.45]) by svr1.postgresql.org (Postfix) with ESMTP id 179DBD1C4DC for ; Thu, 14 Aug 2003 00:12:25 -0300 (ADT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 75936D649; Wed, 13 Aug 2003 20:12:24 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 672F65C0B; Wed, 13 Aug 2003 20:12:24 -0700 (PDT) Date: Wed, 13 Aug 2003 20:12:24 -0700 (PDT) From: Stephan Szabo To: Abdul Wahab Dahalan Cc: Christoph Haller , Subject: Re: How to speeed up the query performance In-Reply-To: <3F3AF940.9000002@mimos.my> Message-ID: <20030813201031.D67777-100000@megazone.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/164 X-Sequence-Number: 14780 On Thu, 14 Aug 2003, Abdul Wahab Dahalan wrote: > Hai Chris! > Thanks for the solution but seem it doesnt work. > (0 rows) returned when I used NOT EXITS but (4 rows) returned > when NOT IN is used................... Maybe you need a set of parenthesis around the old conditions because of the or. > >Try: > >select > >ts.transportid,ts.transporttype,ts.transportcapacity,ts.transportstatus,ts.routecoverage,ts.transportregnumber > > > >from transportsetup ts > >where ts.bizid = 'B126' > >and ts.deletestatus = 0 > >and NOT EXISTS ( select t.transportid > > from transportsetup t,servicedetail s,logisticservice l > > where ts.transportid = t.transportid > > and t.bizid=l.bizid Replace the above with: and (t.bizid=l.bizid > > and l.serviceid=s.serviceid > > and t.transportid=s.transportid > > and t.bizid = 'B126' > > and l.status='Pending' > > or t.bizid=l.bizid > > and l.serviceid=s.serviceid > > and t.transportid=s.transportid > > and t.bizid = 'B126' and l.status='Reserved' ) Add: ) > >order by ts.transporttype;