pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
MULTIPLE OUTER JOIN SYNTAX :-( can't quess it
3+ messages / 2 participants
[nested] [flat]

* MULTIPLE OUTER JOIN SYNTAX :-( can't quess it
@ 2001-04-30 13:55  Constantin Teodorescu <teo@flex.ro>
  0 siblings, 1 reply; 3+ messages in thread

From: Constantin Teodorescu @ 2001-04-30 13:55 UTC (permalink / raw)
  To: pgsql-interfaces

Please excuse for my lack of imagination building SQL selects with OUTER
JOINS but something's unclear for me ...

I have 3 tables, t0, t1 and t2.

Tables are:
authors (alias t0) with (id int2, name text);
books (alias t1) with (author int2, title text);
nicknames (alias t2) with (id int2, nickname text);

I want a select query with them with 2 outer joins like that

t0.id = t1.author
t0.id = t2.id

Tried :
select t0.name, t1.title, t2.nickname from authors t0 left outer JOIN
books t1 ON (t0."id"=t1."author") , authors t0 left outer join nicknames
t2 on (t0."id"=t2."id") 

but it says "author table declared more than once".

with just 1 table it worked for me

Please, could you help me quickly showing me the right syntax?
I'm working to add outer joins to visual query builder in PgAccess.

Constantin Teodorescu
Braila, ROMANIA



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: MULTIPLE OUTER JOIN SYNTAX :-( can't quess it
@ 2001-04-30 14:05  Constantin Teodorescu <teo@flex.ro>
  0 siblings, 0 replies; 3+ messages in thread

From: Constantin Teodorescu @ 2001-04-30 14:05 UTC (permalink / raw)
  To: pgsql-interfaces

Constantin Teodorescu wrote:
> 
> Tried :
> select t0.name, t1.title, t2.nickname from authors t0 left outer JOIN
> books t1 ON (t0."id"=t1."author") , authors t0 left outer join nicknames
> t2 on (t0."id"=t2."id")


:-) After 30 seconds I have found the answer :


select t0.name, t1.title, t2.nickname from authors t0 left outer JOIN
books t1 ON (t0."id"=t1."author") left outer join nicknames
t2 on (t0."id"=t2."id")

Constantin Teodorescu
Braila, ROMANIA



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: MULTIPLE OUTER JOIN SYNTAX :-( can't quess it
@ 2001-04-30 19:05  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Constantin Teodorescu <teo@flex.ro>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 2001-04-30 19:05 UTC (permalink / raw)
  To: Constantin Teodorescu <teo@flex.ro>; +Cc: pgsql-interfaces

Constantin Teodorescu <teo@flex.ro> writes:
> I want a select query with them with 2 outer joins like that
> t0.id = t1.author
> t0.id = t2.id
> Tried :
> select t0.name, t1.title, t2.nickname from authors t0 left outer JOIN
> books t1 ON (t0."id"=t1."author") , authors t0 left outer join nicknames
> t2 on (t0."id"=t2."id") 
> but it says "author table declared more than once".

select t01.name, t01.title, t2.nickname from
    (authors t0 left outer join books t1 on (t0."id"=t1."author")) t01
  left outer join
    nicknames t2 on (t01."id"=t2."id") ;

There are variants but that's the basic idea...

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2001-04-30 19:05 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-04-30 13:55 MULTIPLE OUTER JOIN SYNTAX :-( can't quess it Constantin Teodorescu <teo@flex.ro>
2001-04-30 19:05 ` Tom Lane <tgl@sss.pgh.pa.us>
2001-04-30 14:05 Re: MULTIPLE OUTER JOIN SYNTAX :-( can't quess it Constantin Teodorescu <teo@flex.ro>

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