Chapter 10. Outer Joins, Self-Joins, and Unions: New maneuvers
You only know half of the story about joins. Youâve seen cross joins that return every possible row, and inner joins that return rows from both tables where there is a match. But what you havenât seen are outer joins that give you back rows that donât have matching counterparts in the other table, self-joins which (strangely enough) join a single table to itself, and unions that combine the results of queries. Once you learn these tricks, youâll be able to get at all your data exactly the way you need to. (And we havenât forgotten about exposing the truth about subqueries, either!)
Cleaning up old data
You can get that information with an outer join.
Letâs take a look at what outer joins do, and then weâll show you how to find those professions you arenât using anymore.
An outer joins returns all rows from one of the tables, along with matching information from another table.
With an inner join, youâre comparing rows from two tables, but the order of those two tables doesnât matter.
Letâs briefly review what the equijoin does. We get all the columns that match toy_id
from both tables. It matches up the toy_id
that exists in both tables:
Itâs about left and right
By comparison, outer joins have more to do ...
Get Head First SQL 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.