Oracle 5.0 Reference Manual page 1111

Table of Contents

Advertisement

• If there is no matching row for the right table in the
columns set to
NULL
no counterpart in another table:
SELECT left_tbl.*
FROM left_tbl LEFT JOIN right_tbl ON left_tbl.id = right_tbl.id
WHERE right_tbl.id IS NULL;
This example finds all rows in
all rows in
left_tbl
is declared
NULL. See
NOT
• The
USING(column_list)
and
both contain columns c1, c2, and c3, the following join compares corresponding columns from
b
the two tables:
a LEFT JOIN b USING (c1,c2,c3)
• The
NATURAL [LEFT] JOIN
or a
JOIN
LEFT JOIN
works analogously to
RIGHT JOIN
recommended that you use
The
syntax shown in the join syntax description exists only for compatibility with
{ OJ ... }
ODBC. The curly braces in the syntax should be written literally; they are not metasyntax as used
elsewhere in syntax descriptions.
SELECT left_tbl.*
FROM { OJ left_tbl LEFT OUTER JOIN right_tbl ON left_tbl.id = right_tbl.id }
WHERE right_tbl.id IS NULL;
is similar to JOIN, except that the left table is always read before the right table.
STRAIGHT_JOIN
This can be used for those (few) cases for which the join optimizer puts the tables in the wrong order.
Some join examples:
SELECT * FROM table1, table2;
SELECT * FROM table1 INNER JOIN table2 ON table1.id=table2.id;
SELECT * FROM table1 LEFT JOIN table2 ON table1.id=table2.id;
SELECT * FROM table1 LEFT JOIN table2 USING (id);
SELECT * FROM table1 LEFT JOIN table2 ON table1.id=table2.id
LEFT JOIN table3 ON table2.id=table3.id;
Join Processing Changes in MySQL 5.0.12
Beginning with MySQL 5.0.12, natural joins and joins with USING, including outer join variants, are
processed according to the SQL:2003 standard. The goal was to align the syntax and semantics of
MySQL with respect to
these changes in join processing can result in different output columns for some joins. Also, some
queries that appeared to work correctly in older versions must be rewritten to comply with the standard.
These changes have five main aspects:
• The way that MySQL determines the result columns of
the result of the entire
• Expansion of
SELECT *
• Resolution of column names in
SELECT
is used for the right table. You can use this fact to find rows in a table that have
with an
left_tbl
with no corresponding row in right_tbl). This assumes that
Section 8.3.1.7,
clause names a list of columns that must exist in both tables. If tables
of two tables is defined to be semantically equivalent to an
with a
clause that names all columns that exist in both tables.
USING
JOIN. To keep code portable across databases, it is
LEFT
instead of
LEFT JOIN
and
NATURAL JOIN
JOIN ... USING
clause).
FROM
and
SELECT tbl_name.*
or
NATURAL
1091
Syntax
or
part in a
ON
USING
value that is not present in
id
"LEFT JOIN
and
RIGHT JOIN
RIGHT
JOIN.
according to SQL:2003. However,
or
NATURAL
into a list of selected columns.
joins.
USING
JOIN, a row with all
LEFT
right_tbl
right_tbl.id
Optimization".
INNER
join operations (and thus
USING
(that is,
a

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents