Re: SQL Query

From: Scott Lamb <slamb(at)slamb(dot)org>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: SQL Query
Date: 2002-11-30 08:05:20
Message-ID: 20021130080519.GA5695@calvin.slamb.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Neil Conway 2002-11-30 08:06:16 Re: 7.4 Wishlist
Previous Message Hubert depesz Lubaczewski 2002-11-30 08:03:15 Re: strange pg_stats behaviour?