2.3

The OUTER JOIN Clause

The Outer Join Clause

  • An outer join will return all the rows from one table and only the rows from the other table that match the join condition
  • You can use LEFT JOIN or RIGHT JOIN. If you use LEFT JOIN, all the rows from the table on the left of the equals ( = ) sign will be included in the result set whether the join condition is satisfied or not
  • If you use RIGHT JOIN, all the rows from the table on the right of the equals ( = ) sign will be included in the result set whether the join condition is satisfied or not.

Below is a code snippet of a SQL statement with an outer join clause.

1 USE world;
2 SELECT c.name, c.continent, cl.language
3 FROM country c LEFT JOIN countrylanguage cl
4 ON c.code = cl.CountryCode
5 ORDER BY cl.language ASC; 

Results:

03_joins.png

SELECT c.name, c.continent, cl.language

FROM country c LEFT JOIN countrylanguage cl

ON c.code = cl.CountryCode

This content is provided to you freely by BYU-I Books.

Access it online or download it at https://books.byui.edu/learning_mysql/the_outer_join_claus.