Backend & Databases Comparisonbeginner

Inner Join vs Outer Join: Differences

An inner join keeps only matching rows. An outer join also keeps rows with no match and fills the gaps with NULL. See all four joins on one small example.

6 min read

Our verdict in 30 seconds

An inner join returns only the rows that have a match in both tables. An outer join returns the matching rows plus the rows that have no match, filling the missing side with NULL. A LEFT OUTER JOIN keeps every row from the left table, a RIGHT OUTER JOIN keeps every row from the right table, and a FULL OUTER JOIN keeps every row from both. Use an inner join when you need only matched data and an outer join when you must not lose unmatched rows.

On This Page

Inner join vs outer join is about what happens to rows that have no partner. An inner join keeps only rows that match in both tables and drops the rest. An outer join keeps the unmatched rows too, from one side or both, and fills the missing values with NULL. Every other detail follows from that one idea.

Inner join vs outer join: the difference table

Point Inner join Outer join (LEFT, RIGHT, FULL)
Rows returned Only matching rows Matching rows plus unmatched rows
Unmatched rows Dropped Kept, with NULL for the missing side
NULLs in result Only if the data already had them Added for every missing match
Row count Smallest of the join types Equal to or more than the inner join
Keyword INNER JOIN or just JOIN LEFT JOIN, RIGHT JOIN, FULL OUTER JOIN
Typical question "Students and their fee payments" "All students, with payments if any"
MySQL support Yes LEFT and RIGHT yes; FULL no

In one line: inner join keeps the overlap; outer join keeps the overlap plus what is left over.

The Venn-style picture

Think of two circles. The left circle is every row in the left table. The right circle is every row in the right table. The overlap is the rows that match on the join condition.

  students only      both        fees only
 +-------------+-------------+-------------+
 |    Ravi     |    Asha     |    id 4     |
 |             |    Meena    |             |
 +-------------+-------------+-------------+
   left only       overlap      right only

INNER JOIN       = both                         -> Asha, Meena
LEFT JOIN        = left only + both             -> Ravi, Asha, Meena
RIGHT JOIN       = both + right only            -> Asha, Meena, id 4
FULL OUTER JOIN  = left only + both + right only -> all four

The picture is a memory aid, not a perfect model. A join matches rows by a condition, and one row can match many rows on the other side. But for "which rows survive?", the circles work well.

One example, four joins

Here are two small tables: students, and the fee payments received.

CREATE TABLE students (id INTEGER PRIMARY KEY, name VARCHAR(30));
CREATE TABLE fees (student_id INTEGER, paid INTEGER);

INSERT INTO students VALUES (1, 'Asha'), (2, 'Ravi'), (3, 'Meena');
INSERT INTO fees VALUES (1, 5000), (3, 7000), (4, 3000);
students fees
id name student_id paid
1 Asha 1 5000
2 Ravi 3 7000
3 Meena 4 3000

Ravi has not paid. The payment for student_id 4 belongs to no student in our table, perhaps a record entered with a wrong ID. All results below were run in SQLite.

INNER JOIN: only matches

SELECT s.name, f.paid
FROM students s
INNER JOIN fees f ON f.student_id = s.id
ORDER BY s.id;
name    paid
Asha    5000
Meena   7000

Ravi (no payment) and the payment for ID 4 (no student) are both dropped.

LEFT OUTER JOIN: every student

SELECT s.name, f.paid
FROM students s
LEFT JOIN fees f ON f.student_id = s.id
ORDER BY s.id;
name    paid
Asha    5000
Ravi    NULL
Meena   7000

Every row from the left table (students) is kept. Ravi has no match, so paid is NULL.

RIGHT OUTER JOIN: every payment

SELECT s.name, f.student_id, f.paid
FROM students s
RIGHT JOIN fees f ON f.student_id = s.id
ORDER BY f.student_id;
name    student_id   paid
Asha    1            5000
Meena   3            7000
NULL    4            3000

Every row from the right table (fees) is kept. The payment for ID 4 has no student, so name is NULL. Any RIGHT JOIN can be rewritten as a LEFT JOIN by swapping the tables, and most teams prefer LEFT JOIN for readability.

FULL OUTER JOIN: everything

SELECT s.name, f.student_id, f.paid
FROM students s
FULL OUTER JOIN fees f ON f.student_id = s.id
ORDER BY COALESCE(s.id, f.student_id);
name    student_id   paid
Asha    1            5000
Ravi    NULL         NULL
Meena   3            7000
NULL    4            3000

Unmatched rows from both sides are kept. This is useful for reconciliation, such as comparing a student list with a payment list and finding problems on both sides.

MySQL does not support FULL OUTER JOIN. Combine a LEFT and a RIGHT join with UNION, which also removes the matched rows that appear in both halves:

SELECT s.name, f.student_id, f.paid
FROM students s
LEFT JOIN fees f ON f.student_id = s.id
UNION
SELECT s.name, f.student_id, f.paid
FROM students s
RIGHT JOIN fees f ON f.student_id = s.id
ORDER BY paid;
name    student_id   paid
Ravi    NULL         NULL
NULL    4            3000
Asha    1            5000
Meena   3            7000

Same four rows, sorted by paid this time. If the data could contain fully identical rows that you want to keep, read UNION vs UNION ALL before relying on this pattern.

Left join vs inner join: the mistake that hides rows

This is the most common join bug. Question: show every student, with payments above 4000 if any.

The wrong way:

SELECT s.name, f.paid
FROM students s
LEFT JOIN fees f ON f.student_id = s.id
WHERE f.paid > 4000
ORDER BY s.id;
name    paid
Asha    5000
Meena   7000

Ravi has vanished. The LEFT JOIN kept him with paid = NULL, but then WHERE f.paid > 4000 threw him out, because NULL > 4000 is not true. The LEFT JOIN has quietly become an inner join.

If you want to keep every student and only attach matching payments, put the condition in ON. Here it is with a limit of 6000 so the effect is visible:

SELECT s.name, f.paid
FROM students s
LEFT JOIN fees f ON f.student_id = s.id AND f.paid > 6000
ORDER BY s.id;
name    paid
Asha    NULL
Ravi    NULL
Meena   7000

All three students stay. Asha's 5000 payment did not meet the condition, so she shows NULL, just like Ravi.

Common mistake: Adding a WHERE condition on the right table after a LEFT JOIN. Ask yourself: "Do I want to remove students, or only remove payments?" To remove only payments, put the condition in ON. To remove students, put it in WHERE.

Finding rows with no match

Outer joins answer "who is missing?" questions. Which students have not paid?

SELECT s.name
FROM students s
LEFT JOIN fees f ON f.student_id = s.id
WHERE f.student_id IS NULL;
name
Ravi

Here the WHERE on the right table is correct on purpose: we want only the rows where no match was found. Use IS NULL, never = NULL, which is never true.

Pro tip: Before writing a join, say the question out loud with the word "all" in it. "All students, with their payments" means LEFT JOIN from students. "Students who have paid" means INNER JOIN. The wording tells you the join type.

Join types in SQL at a glance

Join Keeps
INNER JOIN Rows matching in both tables
LEFT [OUTER] JOIN All left rows, plus matches from the right
RIGHT [OUTER] JOIN All right rows, plus matches from the left
FULL [OUTER] JOIN All rows from both tables
CROSS JOIN Every left row paired with every right row
Self join A table joined to itself, such as employees and their managers

For diagrams and more examples of each type, see SQL joins explained. Joins usually follow foreign keys, so primary key vs foreign key is useful background.

For freshers: how to answer in an interview

You can say this in about 30 seconds:

"An inner join returns only rows that match in both tables. An outer join also returns unmatched rows and fills the missing columns with NULL. LEFT keeps all rows from the left table, RIGHT keeps all from the right, and FULL keeps all from both. MySQL has no FULL OUTER JOIN, so I combine LEFT and RIGHT joins with UNION."

Then draw the students and fees tables and show how Ravi and ID 4 appear or disappear. Practise with the SQL joins interview questions and SQL interview questions for freshers. CodeBegun teaches SQL in the data analytics course, in Madhapur, Hyderabad and live online.

Interview note: A favourite follow-up is "If table A has 3 rows and table B has 3 rows, how many rows can an inner join return?" Anywhere from 0 (no matches) to 9 (every row matches every row, as in a join on a column with the same value everywhere). Mention that duplicates in the join column multiply rows.

Frequently Asked Questions

Is LEFT JOIN the same as LEFT OUTER JOIN?
Yes. The word OUTER is optional. LEFT JOIN and LEFT OUTER JOIN mean exactly the same thing, as do RIGHT JOIN and RIGHT OUTER JOIN. Plain JOIN means INNER JOIN.
Which is faster, inner join or outer join?
An inner join can be a little faster because it returns fewer rows and gives the optimiser more freedom. But choose the join by the result you need, not by speed. A wrong result is worse than a slow one; indexes on the join columns matter more.
Does MySQL support FULL OUTER JOIN?
No. MySQL has no FULL OUTER JOIN. You can get the same result by combining a LEFT JOIN and a RIGHT JOIN with UNION. PostgreSQL, SQL Server, Oracle and SQLite 3.39 and later support FULL OUTER JOIN directly.
Why does my LEFT JOIN act like an INNER JOIN?
Usually because a WHERE condition is filtering on a column from the right table, such as WHERE f.paid > 4000. Rows with no match have NULL there, so WHERE removes them. Move that condition into the ON clause if you want to keep unmatched rows.
How do I find rows that have no match?
Use a LEFT JOIN and keep only rows where a right-table column is NULL, such as WHERE f.student_id IS NULL. This is often called an anti-join and answers questions like 'which students have not paid?'

Want to Build Your Career in Data Analytics with AI?

Join CodeBegun and train with working industry engineers — Explore the Data Analytics program

Apply for Demo Class →
Siva Prasad Galaba
Founder, CodeBegun · Staff Engineer

Founder of CodeBegun. 15+ years building Java systems at companies like Crunchyroll. Teaches Java, Spring Boot and system design the way the industry actually works, and mentors students through projects, mock interviews and placement preparation.

Technically reviewed by CodeBegun Technical TeamLast reviewed 5 December 2026 LinkedIn

More comparisons

View all
Chat with us