Unix Technical Forum

multiple outer join

This is a discussion on multiple outer join within the DB2 forums, part of the Database Server Software category; --> Hi, when I try a left outer join on one table everything works fine: select * from (tourist.users u ...


Go Back   Unix Technical Forum > Database Server Software > DB2

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 07:49 AM
Andreas Bauer
 
Posts: n/a
Default multiple outer join

Hi,

when I try a left outer join on one table everything works fine:
select * from (tourist.users u left outer join
tourist.user_extended_info ue on (u.id = ue.id))

But now I need to do another left outer join with a third table, but
this doesn't work (although I found a tutorial on sql where it was
described that way):

select * from (tourist.users u left outer join
tourist.user_extended_info ue on (u.id = ue.id)) t1 left outer join
tourist.profile_for_user p on t1.id = p.id

Toad gives me this error message:
ERROR [42601] [IBM][DB2/NT] SQL0104N Auf "" folgte das unerwartete
Token "JOIN". Zu den möglichen Token gehören: "FROM". SQLSTATE=42601

Any hints on that?

Best regards,

Andi
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 07:49 AM
Knut Stolze
 
Posts: n/a
Default Re: multiple outer join

Andreas Bauer wrote:

> Hi,
>
> when I try a left outer join on one table everything works fine:
> select * from (tourist.users u left outer join
> tourist.user_extended_info ue on (u.id = ue.id))
>
> But now I need to do another left outer join with a third table, but
> this doesn't work (although I found a tutorial on sql where it was
> described that way):
>
> select * from (tourist.users u left outer join
> tourist.user_extended_info ue on (u.id = ue.id)) t1 left outer join
> tourist.profile_for_user p on t1.id = p.id


The correlation name "t1" cannot be used there. This will do:

SELECT *
FROM ( tourist.users u LEFT OUTER JOIN
tourist.user_extended_info ue on (u.id = ue.id) ) LEFT OUTER JOIN
tourist.profile_for_user p on ue.id = p.id

The thing is that the columns in the table produced by the first join do not
have to have unique names. So this is not a valid table in this respect.
If you need to refer to one such column, just use the correlation name of
the table from inside the first join.

Another example:

$ db2 "create table t ( a int, b int )"
$ db2 "select * from ( t t1 left outer join t t2 on t1.a = t2.b ) left outer
join t t3 on t1.a = t3.b"

A B A B A B
----------- ----------- ----------- ----------- ----------- -----------

0 record(s) selected.

(I don't have any data in the table.)

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:49 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com