SELECT <select_list>
FROM
<left_table> <join_type> JOIN <right_table> ON <join_condition>
WHERE <where_condition>
GROUP BY <group_by_list>
HAVING <having_condition>
ORDER BY <order_by_condition>
LIMIT <limit_number>
1.2、SQL执行顺序
FROM <left_table>
ON <join_condition>
<join_type> JOIN <right_table>
WHERE <where_condition>
GROUP BY <group_by_list>
HAVING <having_condition>
SELECT
DISTINCT <select_list>
ORDER BY <order_by_condition>
LIMIT <limit_number>
1.3、SQL执行结果总结
2.2、JOIN查询结果集图解
SELECT <select_list>
FROM tableA A
LEFT JOIN tableB B
ON A.key = B.key;
SELECT <select_list>
FROM tableA A
RIGHT JOIN tableB B
ON A.key = B.key;
SELECT <select_list>
FROM tableA A
INNER JOIN tableB B
ON A.key = B.key;
SELECT <select_list>
FROM tableA A
LEFT JOIN tableB B
ON A.key = B.key
WHERE B.key IS NULL;
SELECT <select_list>
FROM tableA A
RIGHT JOIN tableB B
ON A.key = B.key
WHERE A.key IS NULL;
SELECT <select_list>
FROM tableA A
FULL OUTER JOIN tableB B
ON A.key = B.key
SELECT <select_list>
FROM tableA A
FULL OUTER JOIN tableB B
ON A.key = B.key
WHERE A.key IS NULL OR
B.key IS NULL