Skip to content

JOIN

语法说明

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

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

LEFT JOIN

  • 语法
SELECT [select_list] FROM TableA A LEFT 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
  • 图示

RIGHT JOIN

  • 语法
SELECT [select_list] FROM TableA A RIGHT JOIN TableB B ON A.Key=B.Key
SELECT [select_list] FROM TableA A RIGHT JOIN TableB B ON A.Key=B.Key WHERE A.Key IS NULL
  • 图示

INNER JOIN

  • 语法
select_list] FROM TableA A INNER JOIN TableB B ON A.Key=B.Key
  • 图示

FULL JOIN

  • 语法
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
  • 图示

更多信息,参考: