Unix Technical Forum

TABLE function, OUTER JOINS, and SQL0206N

This is a discussion on TABLE function, OUTER JOINS, and SQL0206N within the DB2 forums, part of the Database Server Software category; --> Friends: I have a query similar in structure to the following: SELECT T1.IBMREQD FROM SYSIBM.SYSDUMMY1 T1 LEFT JOIN TABLE ...


Go Back   Unix Technical Forum > Database Server Software > DB2

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 07:58 AM
jefftyzzer
 
Posts: n/a
Default TABLE function, OUTER JOINS, and SQL0206N

Friends:

I have a query similar in structure to the following:

SELECT
T1.IBMREQD
FROM
SYSIBM.SYSDUMMY1 T1
LEFT JOIN
TABLE
(
SELECT
IBMREQD
FROM
TABLE
(
SELECT
IBMREQD
FROM
SYSIBM.SYSDUMMY1 T2
WHERE
T2.IBMREQD = T1.IBMREQD
) AS T3
)AS T4
ON
T4.IBMREQD = T1.IBMREQD

The LOJ query works fine, but if I change it to FULL OUTER JOIN (or
RIGHT JOIN), I get SQL0206N "T1.IBMREQD" is not valid in the context
where it is used. It appears that T1 is no longer visible to the T3
query.

How can I get it to be?

(DB2 UDB LUW 8.2.3)

Thanks all,

--Jeff

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 07:59 AM
Serge Rielau
 
Posts: n/a
Default Re: TABLE function, OUTER JOINS, and SQL0206N

jefftyzzer wrote:
> Friends:
>
> I have a query similar in structure to the following:
>
> SELECT
> T1.IBMREQD
> FROM
> SYSIBM.SYSDUMMY1 T1
> LEFT JOIN
> TABLE
> (
> SELECT
> IBMREQD
> FROM
> TABLE
> (
> SELECT
> IBMREQD
> FROM
> SYSIBM.SYSDUMMY1 T2
> WHERE
> T2.IBMREQD = T1.IBMREQD
> ) AS T3
> )AS T4
> ON
> T4.IBMREQD = T1.IBMREQD
>
> The LOJ query works fine, but if I change it to FULL OUTER JOIN (or
> RIGHT JOIN), I get SQL0206N "T1.IBMREQD" is not valid in the context
> where it is used. It appears that T1 is no longer visible to the T3
> query.
>
> How can I get it to be?

What would you want it to do?
If you do a RIGHT OUTER join then the RIGHT has to be evaluated before
the left, but it can't be evaluated because the right depends on the left.
Correlation works only across LEFT and INNER joins (left because SQL
parses left to right...).

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-27-2008, 07:59 AM
Art S. Kagel
 
Posts: n/a
Default Was: TABLE function, OUTER JOINS, and SQL0206N

jefftyzzer wrote:
> Friends:
>
> I have a query similar in structure to the following:
>
> SELECT
> T1.IBMREQD
> FROM
> SYSIBM.SYSDUMMY1 T1
> LEFT JOIN
> TABLE
> (
> SELECT
> IBMREQD
> FROM
> TABLE
> (
> SELECT
> IBMREQD
> FROM
> SYSIBM.SYSDUMMY1 T2
> WHERE
> T2.IBMREQD = T1.IBMREQD
> ) AS T3
> )AS T4
> ON
> T4.IBMREQD = T1.IBMREQD

<SNIP>

Serge answered the original question, but I have to comment. Is it me or is
there an unnatural and often unneccessary dependence on the JOIN TABLE(
<some query> ) construct on this list (and other SQL related forums for that
matter)? Isn't Jeff's query above better, more simply and understandably,
and probably more efficiently implemented by a simple LEFT OUTER JOIN? Towit:

SELECT
T1.IBMREQD
FROM
SYSIBM.SYSDUMMY1 AS T1
LEFT JOIN SYSIBM.SYSDUMMY1 AS T2
ON T2.IBMREQD = T1.IBMREQD;

Art S. Kagel
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-27-2008, 07:59 AM
Serge Rielau
 
Posts: n/a
Default Re: Was: TABLE function, OUTER JOINS, and SQL0206N

Art S. Kagel wrote:
> jefftyzzer wrote:
>> Friends:
>>
>> I have a query similar in structure to the following:
>>
>> SELECT
>> T1.IBMREQD
>> FROM
>> SYSIBM.SYSDUMMY1 T1
>> LEFT JOIN
>> TABLE
>> (
>> SELECT
>> IBMREQD
>> FROM
>> TABLE
>> (
>> SELECT
>> IBMREQD
>> FROM
>> SYSIBM.SYSDUMMY1 T2
>> WHERE
>> T2.IBMREQD = T1.IBMREQD
>> ) AS T3
>> )AS T4
>> ON
>> T4.IBMREQD = T1.IBMREQD

> <SNIP>
>
> Serge answered the original question, but I have to comment. Is it me
> or is there an unnatural and often unneccessary dependence on the JOIN
> TABLE( <some query> ) construct on this list (and other SQL related
> forums for that matter)? Isn't Jeff's query above better, more simply
> and understandably, and probably more efficiently implemented by a
> simple LEFT OUTER JOIN? Towit:
>
> SELECT
> T1.IBMREQD
> FROM
> SYSIBM.SYSDUMMY1 AS T1
> LEFT JOIN SYSIBM.SYSDUMMY1 AS T2
> ON T2.IBMREQD = T1.IBMREQD;
>
> Art S. Kagel

Sure,
I think we all assume that the query was stripped to make the point.
Queries cannot always be flattened like that.
One example may be a nested ORDER BY/FETCH FIRST/DISTINCT, ... .

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-27-2008, 07:59 AM
jefftyzzer
 
Posts: n/a
Default Re: TABLE function, OUTER JOINS, and SQL0206N

In my effort to create something that anyone can run, I ended up with
something that invites the question "what the...?" :-)

In my real query, T1 and T2 are different tables. There are several
predicates applied to T1, and I want to filter my T2 rows to just those
that match T1's.

Thanks again,

--Jeff

Serge Rielau wrote:
> jefftyzzer wrote:
> > Friends:
> >
> > I have a query similar in structure to the following:
> >
> > SELECT
> > T1.IBMREQD
> > FROM
> > SYSIBM.SYSDUMMY1 T1
> > LEFT JOIN
> > TABLE
> > (
> > SELECT
> > IBMREQD
> > FROM
> > TABLE
> > (
> > SELECT
> > IBMREQD
> > FROM
> > SYSIBM.SYSDUMMY1 T2
> > WHERE
> > T2.IBMREQD = T1.IBMREQD
> > ) AS T3
> > )AS T4
> > ON
> > T4.IBMREQD = T1.IBMREQD
> >
> > The LOJ query works fine, but if I change it to FULL OUTER JOIN (or
> > RIGHT JOIN), I get SQL0206N "T1.IBMREQD" is not valid in the context
> > where it is used. It appears that T1 is no longer visible to the T3
> > query.
> >
> > How can I get it to be?

> What would you want it to do?
> If you do a RIGHT OUTER join then the RIGHT has to be evaluated before
> the left, but it can't be evaluated because the right depends on the left.
> Correlation works only across LEFT and INNER joins (left because SQL
> parses left to right...).
>
> Cheers
> Serge
>
> --
> Serge Rielau
> DB2 Solutions Development
> IBM Toronto Lab
>
> IOD Conference
> http://www.ibm.com/software/data/ond...ness/conf2006/


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 09:58 AM.


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