• Learning MySQL By Example
  • Introduction
  • 1. How to Retrieve Data From a Single Table
  • 2. How to Retrieve Data from Multiple Tables
  • 3. Using Functions
  • 4. How to Insert, Update, Delete Data in Tables
  • 5. Summary Queries and Aggregate Functions
  • 6. Working With Subqueries
  • 7. SQL Views
  • 8. SQL Indexes
  • Glossary
  • Index
  • Download
  • Translations
  • 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 EdTech Books.

    Access it online or download it at https://edtechbooks.org/learning_mysql/the_outer_join_claus.