JOIN

Description

The JOIN statement is used to combine rows from two or more tables.

The following figure shows seven usages of LEFT JOIN, RIGHT JOIN, INNER JOIN, and OUTER JOIN.

  • LEFT JOIN
SELECT / FROM TableA A LEFT JOIN TableB B ON A.Key=B.Keyleftjoin
SELECT / FROM TableA A LEFT JOIN TableB B ON A.Key=B.Key WHERE B.Key IS NULLleftjoinwhere
  • RIGHT JOIN
SELECT / FROM TableA A RIGHT JOIN TableB B ON A.Key=B.Keyleftjoinwhere
SELECT / FROM TableA A RIGHT JOIN TableB B ON A.Key=B.Key WHERE A.Key IS NULLleftjoinwhere
  • INNER JOIN
SELECT / FROM TableA A INNER JOIN TableB B ON A.Key=B.Keyinnerjoin
  • FULL JOIN
SELECT / FROM TableA A FULL OUTER JOIN TableB B ON A.Key=B.Keyleftjoin
SELECT / FROM TableA A FULL OUTER JOIN TableB B ON A.Key=B.Key WHERE A.Key IS NULL OR B.Key IS NULLfulljoinwhere

For more information, see the reference below: