Re: mere millimetres away

From: lynch(at)lscorp(dot)com (Richard Lynch)
To: Thomas Good <tomg(at)admin(dot)nrnet(dot)org>
Cc: PostgreSQL Lifeline <pgsql-sql(at)postgreSQL(dot)org>
Subject: Re: mere millimetres away
Date: 1998-08-05 22:47:21
Message-ID: v02140b4bb1ee388d586c@[207.152.64.133]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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(at)lscorp(dot)com

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Lynch 1998-08-05 23:42:03 Re: [SQL] Creating table with unique key.
Previous Message Eric McKeown 1998-08-05 22:46:20 Re: [SQL] Creating table with unique key.