Lesson 5 of 15 · 18 min

RIGHT and FULL OUTER JOIN

By the end of this lesson you can rewrite a RIGHT JOIN as a LEFT JOIN, use FULL OUTER JOIN to reconcile two lists, and merge the keys of both sides with COALESCE.

RIGHT JOIN: the mirror image

A RIGHT JOIN keeps every row of the right table (the one after the keyword) and fills the left side with NULL when there is no match. That is all: A RIGHT JOIN B returns the same rows as B LEFT JOIN A, with the columns in a different order.

Because the two are interchangeable, most teams write LEFT JOINs only: the table whose rows must all survive goes first, and a reader can follow a long query top to bottom without flipping directions. You still need to read RIGHT JOIN, because generated SQL and older reports use it.

Included with a Formula Quest membership

This lesson, its 4 graded exercises and every other Members lesson in SQL Quest come with a Formula Quest membership that includes SQL (Single Quest with SQL selected, Quest Trio including SQL, or Quest Unlimited), or with SQL access from your organization.

Free to everyone: all of SQL Foundations and Retrieving and Filtering Data, the first lesson of every track, the playground, the dataset library and the SQL reference. See free lessons