Beginner Topic 15 of 51 Databases
Inner and Outer Joins
Joins differing in how unmatched rows are handled.
How it works
An inner join returns only rows that have a match in both tables. A left outer join returns all rows from the left table, filling columns from the right with NULL where there is no match; a right outer join does the opposite; and a full outer join returns all rows from both. Conditions in ON define matches, while conditions in WHERE filter results afterward, which affects outer joins differently.
Step-by-step walkthrough
- INNER JOIN keeps only rows with a match on both sides.
- LEFT JOIN keeps all left rows, filling NULL when no match.
- RIGHT JOIN keeps all right rows.
- FULL JOIN keeps everything.
- Pick the join by asking which unmatched rows you still want.
Where it is used
Listing all customers including those without orders, finding unmatched records, reconciling two datasets and reports that must show zero counts use outer joins.
Common pitfall
Putting a filter on the right table in the WHERE clause of a left join turns it into an inner join by discarding NULL rows; place it in the ON clause instead. NULLs in join columns never match. Full outer joins are not supported everywhere. Check which side should be preserved and test with missing data.
Where it fits in the course
Inner and Outer Joins is topic 15 of 51 in Databases, rated Beginner. It follows Joins. The next topic is Entity-Relationship Modeling.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Databases quiz.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Databases quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Inner and Outer Joins?
Where do people use Inner and Outer Joins?
What is the most common mistake with Inner and Outer Joins?
What should I learn before this topic?
How can I practice it?
Is Inner and Outer Joins hard to learn?
How long does it take to learn Inner and Outer Joins?
Which topics are related to Inner and Outer Joins?
What should I study after Inner and Outer Joins?
Related topics
- Joins (Databases)
- Entity-Relationship Modeling (Databases)
- GROUP BY and HAVING (Databases)
- Data Types in SQL (Databases)