O'Reilly logo

Sams Teach Yourself MySQL by Chris Newman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required