pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oleg Lebedev <olebedev@waterford.org>
Cc: Postgres SQL Mailing List <pgsql-sql@postgresql.org>
Subject: Re: sequential joins
Date: Fri, 01 Mar 2002 16:47:15 -0700
Message-ID: <3C801303.8DF6A0D1@waterford.org> (raw)
References: <web-814403@davinci.ethosmedia.com>

Ok, here it is:
SELECT *
FROM
activity a
LEFT OUTER JOIN
        (SELECT     username AS artistname,
                            objectid AS userid
        FROM         user) u1
ON a.artist = u1.userid;

After this join, I would have a view, that contains original activity table
data, appended with column artistname, which would contain artist username,
referenced from this activity record.
If I join the result with
        (SELECT     username AS programmername,
                            objectid AS userid
        FROM         user) u2
ON a.programmer = u2.userid
I would have programmername column appended, containing programmers username,
etc.
I hope this clarifies the issue.
thanks,


Josh Berkus wrote:

> Oleg,
>
> > the sub-select statement I was using were not for filtering data (in
> >  which
> > case you can move filtering condition in ON part of the join), but
> >  rather
> > renaming the column 'username' with the name I need in the current
> >  join
> > statement. In this case, columns with new names ('artist',
> >  'designer',
> > 'programmer') would be appended to the overall query result and can
> >  be
> > selected by top-level select statement.
> > This looks like a very clumsy way to do what I need.
> > Any ideas?
>
> No, now I'm confused.  Can you explain better what you are trying to
>  achieve as a result?
>
> -Josh
>
>   ------------------------------------------------------------------------
>
>   ------------------------------------------------------------------------
>
>   ------------------------------------------------------------------------




view thread (6+ messages)

Message-ID: <3C801303.8DF6A0D1@waterford.org>
Permalink:  ../3C801303.8DF6A0D1@waterford.org/
Also on:    postgresql.org/message-id/3C801303.8DF6A0D1@waterford.org

 · 

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: olebedev@waterford.org
  Subject: Re: sequential joins
  In-Reply-To: <3C801303.8DF6A0D1@waterford.org>

* 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