12. Outer Joins

Keywords Introduced

LEFT JOIN  •  RIGHT JOIN  •  FULL JOIN  •  CROSS JOIN

We now advance from inner joins to outer joins. The main restriction of inner joins is that they require a match in all tables being joined to show any results. If you’re joining a Customers table to an Orders table, no data is shown for the customer if that customer hasn’t yet placed an order. This may seem like a relatively unimportant problem, but it often becomes significant with different types of data.

To use a different example, let’s say we have an Orders table and a Refunds table. The Refunds table is related to the Orders table by OrderID. In other words, all refunds are tied to a specific order. The refund can’t exist unless the order exists. ...

Get The Language of SQL, Second Edition 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.