Re: join question

From: Manfred Koizar <mkoi-pg(at)aon(dot)at>
To: nathan(at)ncyoung(dot)com
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: join question
Date: 2002-11-28 08:10:26
Message-ID: grjbuugdh8fr7t7rkekl7jngjlksi3itb9@4ax.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, 27 Nov 2002 09:37:07 -0800, Nathan Young <nyoung(at)asis(dot)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.

Servus
Manfred

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Christoph Haller 2002-11-28 16:14:06 Re: retrieving specific info. from one column and locating it in another
Previous Message Peter Childs 2002-11-27 20:04:40 Re: Question on SQL and pg_-tables