Re: join/case

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: jtx <jtx(at)hatesville(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: join/case
Date: 2003-05-31 13:08:31
Message-ID: 20030531130831.GA31995@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Fri, May 30, 2003 at 16:03:44 -0700,
jtx <jtx(at)hatesville(dot)com> wrote:
> Basically, I have something like this:
>
> Select o.id,o.num_purch,o.program from orders o left join lists l on
> l.order_id=o.id where o.uid=1 and o.status!='closed'
>
> However, I want to throw an extra conditional in there that says if
> l.status='processing', then don't return anything. So, I tried:

The straight forward way to do this is do just do what you described.
Make the join a subselect (keeping l.status) and then select from that
where status <> 'processing. The result looks like:

select id, num_purch, program
from
(select o.id,o.num_purch,o.program,l.status
from orders o left join lists l on l.order_id=o.id
where o.uid=1 and o.status!='closed') as j
where
status <> 'processing';

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Danny Su 2003-06-01 04:02:22 generic return for functions
Previous Message Bruce Momjian 2003-05-31 02:31:38 Re: [PERFORM] Yet Another (Simple) Case of Index not used