From: lynch@lscorp.com
To: Thomas Good <tomg@admin.nrnet.org>
Cc: PostgreSQL Lifeline <pgsql-sql@postgreSQL.org>
Subject: Re: mere millimetres away
Date: Wed, 5 Aug 1998 17:47:21 -0500
Message-ID: <v02140b4bb1ee388d586c@[207.152.64.133]> (raw)
At 4:15 PM 8/5/98, Thomas Good wrote:
>Rich,
>---------------------------------------------------------
>I got the following to work fine (so I had to break it!):
>---------------------------------------------------------
>SELECT tr_id, tr_date
>FROM crtrd1 ALIAS1
>WHERE ALIAS1.tr_unit = 'SMA'
> AND (ALIAS1.tr_type = 'A' OR ALIAS1.tr_type = 'I')
> AND ALIAS1.tr_id NOT IN (
> SELECT tr_id
> FROM crtrd1 ALIAS2
> WHERE ALIAS2.tr_unit = 'SMA'
> AND ALIAS2.tr_id = ALIAS1.tr_id
> AND (ALIAS2.tr_type = 'T' OR ALIAS2.tr_type = 'O')
> AND ALIAS2.tr_date > ALIAS1.tr_date
> )
>ORDER BY tr_date DESC;
>
>----------------------------------------------------------------------
>I need to include the patient names so I tried a join to another table
>----------------------------------------------------------------------
> SELECT crtrd1.tr_id, tr_date, client_lname, client_fname
> FROM crtrd1 ALIAS1, svcrd1 ALIAS0
> WHERE ALIAS1.tr_unit = 'SMA'
> AND ALIAS1.tr_id = ALIAS0.tr_id
> AND (ALIAS1.tr_type = 'A' OR ALIAS1.tr_type = 'I')
> AND NOT EXISTS(
> SELECT crtrd1.tr_id
> FROM crtrd1 ALIAS2
> WHERE ALIAS2.tr_unit = 'SMA'
> AND ALIAS2.tr_id = ALIAS1.tr_id
> AND (ALIAS2.tr_type = 'T' OR ALIAS2.tr_type = 'O')
> AND ALIAS2.tr_date > ALIAS1.tr_date
> )
>ORDER BY tr_date DESC;
You should try doing analyze on these things to see why they are taking so
long... I don't see anything wrong with this one, but I'm *NOT* an SQL
expert.
It may be trying to create a table that's just too large...
--
--
-- "TANSTAAFL" Rich lynch@lscorp.com
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-sql@postgresql.org
Cc: lynch@lscorp.com, tomg@admin.nrnet.org
Subject: Re: mere millimetres away
In-Reply-To: <v02140b4bb1ee388d586c@[207.152.64.133]>
References: <v02140b4bb1ee388d586c@[207.152.64.133]>
* 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