57,064
社区成员
发帖
与我相关
我的任务
分享
table_references:
table_reference [, table_reference] …
table_reference:
table_factor
| join_table
table_factor:
tbl_name [[AS] alias]
[{USE|IGNORE|FORCE} INDEX (key_list)]
| ( table_references )
| { OJ table_reference LEFT OUTER JOIN table_reference
ON conditional_expr }
join_table:
table_reference [INNER | CROSS] JOIN table_factor [join_condition]
| table_reference STRAIGHT_JOIN table_factor
| table_reference STRAIGHT_JOIN table_factor ON condition
| table_reference LEFT [OUTER] JOIN table_reference join_condition
| table_reference NATURAL [LEFT [OUTER]] JOIN table_factor
| table_reference RIGHT [OUTER] JOIN table_reference join_condition
| table_reference NATURAL [RIGHT [OUTER]] JOIN table_factor
join_condition:
ON conditional_expr
| USING (column_list)
SELECT STRAIGHT_JOIN
r.regionName, c.cityName, d.departmentName
FROM
m_city c LEFT JOIN m_region r ON c.regionId = r.id,
m_department d
WHERE c.id = d.cityId
ORDER BY r.regionName, c.cityName, d.departmentNameSELECT STRAIGHT_JOIN
r.regionName, c.cityName, d.departmentName
FROM
m_department d,
m_city c LEFT JOIN m_region r ON c.regionId = r.id
WHERE c.id = d.cityId
ORDER BY r.regionName, c.cityName, d.departmentName
mysql> explain select * from t left join book on t.a=book.id;
+----+-------------+-------+--------+---------------+---------+---------+------------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+--------+---------------+---------+---------+------------+------+-------+
| 1 | SIMPLE | t | ALL | NULL | NULL | NULL | NULL | 4 | |
| 1 | SIMPLE | book | eq_ref | PRIMARY | PRIMARY | 4 | mybook.t.a | 1 | |
+----+-------------+-------+--------+---------------+---------+---------+------------+------+-------+
2 rows in set (0.00 sec)
mysql> explain select * from book right join t on t.a=book.id;
+----+-------------+-------+--------+---------------+---------+---------+------------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+--------+---------------+---------+---------+------------+------+-------+
| 1 | SIMPLE | t | ALL | NULL | NULL | NULL | NULL | 4 | |
| 1 | SIMPLE | book | eq_ref | PRIMARY | PRIMARY | 4 | mybook.t.a | 1 | |
+----+-------------+-------+--------+---------------+---------+---------+------------+------+-------+
2 rows in set (0.00 sec)
mysql>