JOIN

语法说明

JOIN 用于把来自两个或多个表的行结合起来。

下图展示了 LEFT JOINRIGHT JOININNER JOIN、和 OUTER JOIN

  • LEFT JOIN
SELECT [select_list] FROM TableA A LEFT JOIN TableB B ON A.Key=B.Keyleftjoin
SELECT [select_list] FROM TableA A LEFT JOIN TableB B ON A.Key=B.Key WHERE B.Key IS NULLleftjoinwhere
  • RIGHT JOIN
SELECT [select_list] FROM TableA A RIGHT JOIN TableB B ON A.Key=B.Keyleftjoinwhere
SELECT [select_list] FROM TableA A RIGHT JOIN TableB B ON A.Key=B.Key WHERE A.Key IS NULLleftjoinwhere
  • INNER JOIN
SELECT [select_list] FROM TableA A INNER JOIN TableB B ON A.Key=B.Keyinnerjoin
  • FULL JOIN
SELECT [select_list] FROM TableA A FULL OUTER JOIN TableB B ON A.Key=B.Keyleftjoin
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 NULLfulljoinwhere

更多信息,参考: