Oracle 5.0 Reference Manual page 1112

Table of Contents

Advertisement

• Transformation of
NATURAL
• Resolution of column names in the
The following list provides more detail about several effects of the 5.0.12 change in join processing.
The term "previously" means "prior to MySQL 5.0.12."
• The columns of a
NATURAL
redundant output columns no longer appear, and the order of columns for
be different from before.
Consider this set of statements:
CREATE TABLE t1 (i INT, j INT);
CREATE TABLE t2 (k INT, j INT);
INSERT INTO t1 VALUES(1,1);
INSERT INTO t2 VALUES(1,1);
SELECT * FROM t1 NATURAL JOIN t2;
SELECT * FROM t1 JOIN t2 USING (j);
Previously, the statements produced this output:
+------+------+------+------+
| i
| j
| k
+------+------+------+------+
|
1 |
1 |
+------+------+------+------+
+------+------+------+------+
| i
| j
| k
+------+------+------+------+
|
1 |
1 |
+------+------+------+------+
In the first
statement, column
SELECT
so, according to standard SQL, it should appear only once in the output, not twice. Similarly, in the
second SELECT statement, column
in the output, not twice. But in both cases, the redundant column is not eliminated. Also, the order of
the columns is not correct according to standard SQL.
Now the statements produce this output:
+------+------+------+
| j
| i
| k
+------+------+------+
|
1 |
1 |
+------+------+------+
+------+------+------+
| j
| i
| k
+------+------+------+
|
1 |
1 |
+------+------+------+
The redundant column is eliminated and the column order is correct according to standard SQL:
• First, coalesced common columns of the two joined tables, in the order in which they occur in the
first table
• Second, columns unique to the first table, in order in which they occur in that table
• Third, columns unique to the second table, in order in which they occur in that table
The single result column that replaces two common columns is defined using the coalesce
operation. That is, for two
COALESCE(t1.a,
COALESCE(x, y) = (CASE WHEN V1 IS NOT NULL THEN V1 ELSE V2 END)
SELECT
or
joins into
USING
condition of a
ON
join or a
USING
| j
|
1 |
1 |
| j
|
1 |
1 |
appears in both tables and thus becomes a join column,
j
is named in the
j
|
1 |
|
1 |
and
the resulting single join column
t1.a
t2.a
t2.a), where:
1092
Syntax
JOIN ...
ON.
JOIN ...
ON.
join may be different from previously. Specifically,
clause and should appear only once
USING
expansion may
SELECT *
is defined as
a
a =

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents