pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Manfred Koizar <mkoi-pg@aon.at>
To: nathan@ncyoung.com
Cc: pgsql-sql@postgresql.org
Subject: Re: join question
Date: Thu, 28 Nov 2002 09:10:26 +0100
Message-ID: <grjbuugdh8fr7t7rkekl7jngjlksi3itb9@4ax.com> (raw)
In-Reply-To: <98FCPJ2YA0B9EDSOVU5ZURIFVR76US2X.3de502c3@inky>
References: <20021126080514.C77510-100000@megazone23.bigpanda.com>
	<98FCPJ2YA0B9EDSOVU5ZURIFVR76US2X.3de502c3@inky>

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.

Servus
 Manfred



view thread (22+ messages)  latest in thread

Message-ID: <grjbuugdh8fr7t7rkekl7jngjlksi3itb9@4ax.com>
Permalink:  ../grjbuugdh8fr7t7rkekl7jngjlksi3itb9@4ax.com/
Also on:    postgresql.org/message-id/grjbuugdh8fr7t7rkekl7jngjlksi3itb9@4ax.com

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: mkoi-pg@aon.at, nathan@ncyoung.com
  Subject: Re: join question
  In-Reply-To: <grjbuugdh8fr7t7rkekl7jngjlksi3itb9@4ax.com>

* 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