Oracle 5.0 Reference Manual page 688

Table of Contents

Advertisement

ON t1.a=t2.a
transforms into the expression:
(t1 LEFT JOIN t2 ON t1.a=t2.a) LEFT JOIN t3
ON t2.b=t3.b OR t2.b IS NULL
Yet, the two expressions are not equivalent. To see this, suppose that the tables t1, t2, and
the following state:
• Table
contains rows (1),
t1
• Table
contains row
t2
• Table
contains row
t3
In this case, the first expression returns a result set including the rows (1,1,101,101),
(2,NULL,NULL,NULL), whereas the second expression returns the rows (1,1,101,101),
(2,NULL,NULL,101):
mysql>
SELECT *
->
FROM t1
->
LEFT JOIN
->
(t2 LEFT JOIN t3 ON t2.b=t3.b OR t2.b IS NULL)
->
ON t1.a=t2.a;
+------+------+------+------+
| a
| a
| b
+------+------+------+------+
|
1 |
1 |
101 |
|
2 | NULL | NULL | NULL |
+------+------+------+------+
mysql>
SELECT *
->
FROM (t1 LEFT JOIN t2 ON t1.a=t2.a)
->
LEFT JOIN t3
->
ON t2.b=t3.b OR t2.b IS NULL;
+------+------+------+------+
| a
| a
| b
+------+------+------+------+
|
1 |
1 |
101 |
|
2 | NULL | NULL |
+------+------+------+------+
In the following example, an outer join operation is used together with an inner join operation:
t1 LEFT JOIN (t2, t3) ON t1.a=t2.a
That expression cannot be transformed into the following expression:
t1 LEFT JOIN t2 ON t1.a=t2.a, t3.
For the given table states, the two expressions return different sets of rows:
mysql>
SELECT *
->
FROM t1 LEFT JOIN (t2, t3) ON t1.a=t2.a;
+------+------+------+------+
| a
| a
| b
+------+------+------+------+
|
1 |
1 |
101 |
|
2 | NULL | NULL | NULL |
+------+------+------+------+
mysql>
SELECT *
->
FROM t1 LEFT JOIN t2 ON t1.a=t2.a, t3;
+------+------+------+------+
| a
| a
| b
+------+------+------+------+
|
1 |
1 |
101 |
Optimizing
SELECT
(2)
(1,101)
(101)
| b
|
101 |
| b
|
101 |
101 |
| b
|
101 |
| b
|
101 |
668
Statements
have
t3

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents