Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 624AA475CEE for ; Sat, 30 Nov 2002 03:03:36 -0500 (EST) Received: from calvin.slamb.org (calvin.slamb.org [216.136.66.56]) by postgresql.org (Postfix) with ESMTP id 71D5C47580B for ; Sat, 30 Nov 2002 03:03:35 -0500 (EST) Received: by calvin.slamb.org (Postfix, from userid 500) id 363526FC98; Sat, 30 Nov 2002 02:05:20 -0600 (CST) Date: Sat, 30 Nov 2002 02:05:20 -0600 From: Scott Lamb To: pgsql-general@postgresql.org Subject: Re: SQL Query Message-ID: <20021130080519.GA5695@calvin.slamb.org> References: <1038597838.1488.23.camel@localhost.localdomain> <20021130074544.GA17708@temp.joelburton.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20021130074544.GA17708@temp.joelburton.com> User-Agent: Mutt/1.4i X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/1464 X-Sequence-Number: 33883 On Sat, Nov 30, 2002 at 02:45:44AM -0500, Joel Burton wrote: > You can rewrite this w/EXISTS or with a multi-table join, and it > should perform better: > > SELECT t2.* > FROM trans AS t1, > trans AS t2 > WHERE > t1.chart_id = 10074 > AND t1.trans_id = t2.trans_id > AND t2.amount >= 0 > AND t2.transdate BETWEEN '2002-07-01' AND '2002-09-30' Doesn't that need a "distinct" to be equivalent to the exists query? If there are two 10074 rows with the same trans_id, I think all rows with that trans_id would be returned twice otherwise. -- Scott Lamb