INFO: Restrictions for Multi-Table Outer Joins (45301)



The information in this article applies to:

  • Microsoft SQL Server 4.2x
  • Microsoft SQL Server 6.0
  • Microsoft SQL Server 6.5

This article was previously published under Q45301

SUMMARY

The following information discusses how many tables can be involved in an outer join, and the restrictions involved.

MORE INFORMATION

Outer joins cannot be nested (t1*=t2*=t3 is illegal), but multiple outer joins are permitted if they aren't nested (t1=*t2*=t3 is allowed).

Inner joins cannot be nested inside the outer join (t1*=t2=t3 is illegal, but t1=t2*=t3 is allowed).

t1*=t2=*t3 is also permitted. It takes the Cartesian product of t1 and t3, then outer-joins the result to t2.

As long as the semantic rules are not violated, the limit is 16 tables, just as with an inner join.

The semantics regarding outer joins can be represented graphically with the tables as nodes and the joins as arcs between the nodes. Outer joins are directed arcs with the arrow pointing to the "inner" table of the pair.

The following is a graphic representation:
select * from t1,t2 where t1.c1*=t2.c1   is   t1 --> t2
select * from t1,t2 where t1.c1=*t2.c1   is   t1 <-- t2
select * from t1,t2 where t1.c1=t2.c1    is   t1 --- t2

illegal                               legal

t1-->t2-->t3     t1-->t2<--t3         t1-->t2<--t3        t1-->t2<--t3
t1<--t2<--t3      |        ^          t1<--t2-->t3         |        |
t1-->t2---t3      |        |          t1---t2-->t3         +--------+
                  +--------+

     t3            t3                      t3                 t3
      ^             |                       ^                  |
      |             v                       |                  v
t2<--t1<--t4  t2-->t1-->t4            t2<--t1-->t4       t2-->t1<--t4
      |             ^                       |                  ^
      v             |                       v                  |
     t5            t5                      t5                 t5
				

Arcs may enter a node or arcs may leave a node, but arcs cannot leave a node that has any arcs entering it.

Modification Type:MinorLast Reviewed:3/14/2005
Keywords:kbinfo kbProgramming KB45301