what type of join is needed when you wish to include rows that do not have matching values?
An outer join is used when you want to include rows that do not have matching values. In classic exam-style wording, the correct choice is:
- Outer join (this includes:
- Left outer join
- Right outer join
- Full outer join)
These joins keep âunmatchedâ rows and fill the missing side with NULL
values, which is exactly what you need when you want to see rows even if no
match exists in the other table.
Quick Scoop: Why âouter joinâ?
- An inner join only returns rows where there is a match in both tables.
- An outer join returns the matches plus the non-matching rows (with
NULLs on the missing side). - Thatâs why, when youâre asked âwhat type of join is needed when you wish to include rows that do not have matching values?â , the intended textbook answer is outer join.
Mini breakdown of outer joins
- LEFT OUTER JOIN :
Returns all rows from the left table, and matched rows from the right. Unmatched right-side rows becomeNULL.
- RIGHT OUTER JOIN :
Mirror of left join: keeps all from the right table, withNULLs on the left when no match exists.
- FULL OUTER JOIN :
Returns all rows from both tables; where thereâs no match on either side, the missing side isNULL.
A simple mental story: imagine two guest lists from two different events. An inner join shows only people who attended both events, while an outer join lets you also see everyone who only attended one of them.
Example snippet
sql
SELECT *
FROM Customers c
LEFT OUTER JOIN Orders o
ON c.CustomerID = o.CustomerID;
This returns all customers, even those who never placed an order; their order
columns will be NULL, showing the non-matching rows clearly.
TL;DR:
The join youâre looking for is an outer join , because it preserves rows
even when there is no matching value in the other table.
Information gathered from public forums or data available on the internet and portrayed here.