Re: SQL Query - Mailing list pgsql-general

From Scott Lamb
Subject Re: SQL Query
Date
Msg-id 20021130080519.GA5695@calvin.slamb.org
Whole thread Raw
In response to Re: SQL Query  (Joel Burton <joel@joelburton.com>)
Responses Re: SQL Query  (Joel Burton <joel@joelburton.com>)
List 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

pgsql-general by date:

Previous
From: Joel Burton
Date:
Subject: Re: SQL Query
Next
From: Hubert depesz Lubaczewski
Date:
Subject: Re: strange pg_stats behaviour?