Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Get to know the data
JOIN revisited
LEFT JOIN
RIGHT JOIN
FULL JOIN
15. FULL JOIN explained
OUTER JOINS
Aliases for tables

Instruction

Excellent! Another joining method is FULL JOIN. This type of JOIN returns all rows from both tables and combines the rows when there is a match. In other words, FULL JOIN is a union of LEFT JOIN and RIGHT JOIN.

Let's see an example:

SELECT
  *
FROM Car
FULL JOIN Person
  ON Car.OwnerID = Person.ID;

The result may look like this:

Car Person
Id Brand OwnerId Id Name
1 Ford 3 3 Megan Donald
2 Opel 5 5 John Smith
3 Nissan 4 4 Andrew Black
4 Skoda NULL NULL NULL
5 BMW NULL NULL NULL
6 Citroen NULL NULL NULL
NULL NULL NULL 1 Sylvia Green
NULL NULL NULL 2 Martin Dean
NULL NULL NULL 6 Adam Scott

The pink rows are returned by an INNER JOIN.
The blue rows would be added to pink rows by a LEFT JOIN.
The purple rows would be added to pink rows by a RIGHT JOIN.

A FULL JOIN returns all rows from the table above.

Exercise

Show the room each student is assigned to. Include students without a room and rooms without students. Show only two columns: RoomNumber and Name.