Oracle 5.0 Reference Manual page 1114

Table of Contents

Advertisement

• With respect to determining which columns to display for
not semantically identical. The
whereas the
join selects all columns from all tables. For the preceding
ON
selects these values:
COALESCE(a.c1,b.c1), COALESCE(a.c2,b.c2), COALESCE(a.c3,b.c3)
For the
join,
ON
SELECT *
a.c1, a.c2, a.c3, b.c1, b.c2, b.c3
With an inner join,
both columns will have the same value. With an outer join (such as
columns can be NULL. That column will be omitted from the result.
• The evaluation of multi-way natural joins differs in a very important way that affects the result of
or
NATURAL
USING
t1(a,b), t2(c,b), and
Suppose also that you have this
SELECT ... FROM t1 NATURAL JOIN t2 NATURAL JOIN t3;
Previously, the left operand of the second join was considered to be t2, whereas it should be the
nested join
(t1 NATURAL JOIN
columns only in t2, and, if
join columns. Thus, previously, the preceding query was transformed to the following equi-join:
SELECT ... FROM t1, t2, t3
WHERE t1.b = t2.b AND t2.c = t3.c;
That join is missing one more equi-join predicate
not the empty result that it should. The correct equivalent query is this:
SELECT ... FROM t1, t2, t3
WHERE t1.b = t2.b AND t2.c = t3.c AND t1.a = t3.a;
If you require the same query result in current versions of MySQL as in older versions, rewrite the
natural join as the first equi-join.
• Previously, the comma operator (,) and
was interpreted as
t1, t2 JOIN t3
so the expression is interpreted as
use an
clause, because that clause can refer only to columns in the operands of the join, and the
ON
change in precedence changes interpretation of what those operands are.
Example:
CREATE TABLE t1 (i1 INT, j1 INT);
CREATE TABLE t2 (i2 INT, j2 INT);
CREATE TABLE t3 (i3 INT, j3 INT);
INSERT INTO t1 VALUES(1,1);
INSERT INTO t2 VALUES(1,1);
INSERT INTO t3 VALUES(1,1);
SELECT * FROM t1, t2 JOIN t3 ON (t1.i1 = t3.i3);
Previously, the
SELECT
takes precedence, so the operands for the
JOIN
column in either of the operands, the result is an
error. To allow the join to be processed, group the first two tables explicitly with parentheses so that
the operands for the
SELECT * FROM (t1, t2) JOIN t3 ON (t1.i1 = t3.i3);
SELECT
join selects the coalesced value of corresponding columns,
USING
selects these values:
COALESCE(a.c1,b.c1)
joins and that can require query rewriting. Suppose that you have three tables
that each have one row: t1(1,2), t2(10,2), and t3(7,10).
t3(a,c)
NATURAL JOIN
t2). As a result, the columns of
has common columns with t1, these columns are not used as equi-
t3
JOIN
((t1, t2) JOIN
(t1, (t2 JOIN
was legal due to the implicit grouping of
clause are
ON
(t1,t2)
1094
Syntax
SELECT *
[878]
is the same as either
on the three tables:
t3
t3.a). As a result, it produces one row,
(t1.a =
both had the same precedence, so the join expression
t3). Now
t3)). This change affects statements that
t1,t2
clause are
and t3. Because
ON
t2
Unknown column 't1.i1' in 'on clause'
and t3:
expansion, the two joins are
join,
USING
SELECT *
or
because
a.c1
b.c1
JOIN), one of the two
LEFT
are checked for common
has higher precedence,
JOIN
as (t1,t2). Now the
t1.i1
is not a

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents