SELECT
Syntax
1092
• Transformation of
NATURAL
or
USING
joins into
JOIN ... ON
.
• Resolution of column names in the
ON
condition of a
JOIN ... ON
.
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
join or a
USING
join may be different from previously. Specifically,
redundant output columns no longer appear, and the order of columns for
SELECT *
expansion may
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 | j |
+------+------+------+------+
| 1 | 1 | 1 | 1 |
+------+------+------+------+
+------+------+------+------+
| i | j | k | j |
+------+------+------+------+
| 1 | 1 | 1 | 1 |
+------+------+------+------+
In the first
SELECT
statement, column
j
appears in both tables and thus becomes a join column,
so, according to standard SQL, it should appear only once in the output, not twice. Similarly, in the
second SELECT statement, column
j
is named in the
USING
clause and should appear only once
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 | 1 |
+------+------+------+
+------+------+------+
| j | i | k |
+------+------+------+
| 1 | 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
t1.a
and
t2.a
the resulting single join column
a
is defined as
a =
COALESCE(t1.a, t2.a)
, where:
COALESCE(x, y) = (CASE WHEN V1 IS NOT NULL THEN V1 ELSE V2 END)
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...