LearnViz CompSci
Home / Learn / Databases / Inner and Outer Joins

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

  1. INNER JOIN keeps only rows with a match on both sides.
  2. LEFT JOIN keeps all left rows, filling NULL when no match.
  3. RIGHT JOIN keeps all right rows.
  4. FULL JOIN keeps everything.
  5. 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

How to study this topic

  1. Read the explanation above and restate the definition in your own words.
  2. Open the interactive lesson and answer its mini quiz.
  3. Read the common pitfall, then write a short example that avoids it.
  4. 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?
Joins differing in how unmatched rows are handled. It belongs to Databases and is a beginner-level topic.
Where do people use Inner and Outer Joins?
Listing all customers including those without orders, finding unmatched records, reconciling two datasets and reports that must show zero counts use outer joins.
What is the most common mistake with Inner and Outer Joins?
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.
What should I learn before this topic?
Start with Joins, the topic just before it in Databases.
How can I practice it?
Answer the mini quiz in the interactive lesson, then take the Databases quiz.
Is Inner and Outer Joins hard to learn?
It is a Beginner topic, so it works as an entry point. If the terms are new, read the explanation twice and try the visualizer before the quiz.
How long does it take to learn Inner and Outer Joins?
Most learners can read the explanation and finish the interactive lesson in under an hour. Fluency comes from applying the idea, so plan a few short practice sessions with the quiz.
Which topics are related to Inner and Outer Joins?
Joins, Entity-Relationship Modeling, GROUP BY and HAVING are closely connected. The full list is in the related topics section of this page.
What should I study after Inner and Outer Joins?
Continue with Entity-Relationship Modeling, the next topic in Databases.

Related topics