Re: join question - Mailing list pgsql-sql

From Manfred Koizar
Subject Re: join question
Date
Msg-id grjbuugdh8fr7t7rkekl7jngjlksi3itb9@4ax.com
Whole thread Raw
In response to Re: join question  (Nathan Young <nyoung@asis.com>)
List pgsql-sql
On Wed, 27 Nov 2002 09:37:07 -0800, Nathan Young <nyoung@asis.com>
wrote:
>OK, that works great, but I was told that I should avoid sub-selects when 
>possible for performance reasons.
>>
>> select member.memberId, member.name from member left outer join
>>  (select * from payment where yearPaid=2002) as a using (memberId) where
>>  yearPaid is null;

Nathan,
if you want a version without a subselect, try
   SELECT m.memberId, m.name   FROM member AS m LEFT OUTER JOIN        payment AS p ON p.yearPaid=2002 AND
m.memberId=p.memberId  WHERE p.memberId IS NULL;
 

though I don't know whether it is faster.

ServusManfred


pgsql-sql by date:

Previous
From: Peter Childs
Date:
Subject: Re: Question on SQL and pg_-tables
Next
From: Christoph Haller
Date:
Subject: Re: retrieving specific info. from one column and locating it in another