Outer Joins

Most joins return rows based on pairs of records from the two joined tables according to a given relationship. The outer join is different: All the rows from one table are returned, regardless of whether the relationship condition finds a matching row in the second table. When no corresponding record is found, columns that would otherwise contain values from the second table contain NULL.

Outer joins are useful in producing reports when you do not want to exclude a record from the result if it does not have any corresponding data in a joined table.

The following example uses an outer join to produce a report of the customer orders placed in the month of February only:

mysql>  SELECT c.name, o.order_date
    ->  FROM customers c
    ->  LEFT ...

Get Sams Teach Yourself MySQL now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.