INNER JOIN vs OUTER JOIN

SQL

What is an INNER JOIN?

Returns only rows with matching values from both tables, showing common data.

What is an OUTER JOIN?

Returns matching rows plus non-matching rows from one or both tables with NULLs.

Types of Outer Joins

LEFT JOIN returns all rows from left table; RIGHT JOIN from right; FULL JOIN from both.

How INNER JOIN works

Combines rows where columns match in both tables, excluding unmatched rows.

Combines rows where columns match in both tables, excluding unmatched rows.

How OUTER JOIN works

Includes all rows from one or both tables, filling unmatched sides with NULL values.

Use INNER JOIN when

You need only related data from both tables, focusing on intersection of data.

Use OUTER JOIN when

You want complete data, including unmatched records with nulls for missing matches.

Performance Note

INNER JOINs are usually faster since they retrieve only matching data, unlike OUTER JOINs.