pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Scott Lamb <slamb@slamb.org>
To: pgsql-general@postgresql.org
Subject: Re: SQL Query
Date: Sat, 30 Nov 2002 02:05:20 -0600
Message-ID: <20021130080519.GA5695@calvin.slamb.org> (raw)
In-Reply-To: <20021130074544.GA17708@temp.joelburton.com>
References: <1038597838.1488.23.camel@localhost.localdomain>
	<20021130074544.GA17708@temp.joelburton.com>

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



view thread (45+ messages)  latest in thread

Message-ID: <20021130080519.GA5695@calvin.slamb.org>
Permalink:  ../20021130080519.GA5695@calvin.slamb.org/
Also on:    postgresql.org/message-id/20021130080519.GA5695@calvin.slamb.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: slamb@slamb.org
  Subject: Re: SQL Query
  In-Reply-To: <20021130080519.GA5695@calvin.slamb.org>
  References: <1038597838.1488.23.camel@localhost.localdomain> <20021130074544.GA17708@temp.joelburton.com> <20021130080519.GA5695@calvin.slamb.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox