Understanding INNER JOIN and LEFT JOIN in SQL: Beginner-Friendly Guide

INNER JOIN returns only the rows where matching values exist in both tables.

  • If there is no match, that row is ignored.
  • Think: “Show me only common records.”

LEFT JOIN returns all rows from the left table, and the matching rows from the right table.

  • If there’s no match in the right table, it will show NULL.
  • Think: “Show me everything from the left side, and add details from the right side if available.”

Example

Let’s say we have two tables:

students

student_idname
1Ramesh
2Priya
3Amit

marks

mark_idstudent_idsubjectmarks
11Maths90
22Science85

INNER JOIN Example

sql

SELECT students.name, marks.subject, marks.marks
FROM students
INNER JOIN marks
ON students.student_id = marks.student_id;

Result:

namesubjectmarks
RameshMaths90
PriyaScience85
  • Only students who have marks appear.
  • Amit is missing because he has no marks record.

LEFT JOIN Example

sql

SELECT students.name, marks.subject, marks.marks
FROM students
LEFT JOIN marks
ON students.student_id = marks.student_id;

Result:

namesubjectmarks
RameshMaths90
PriyaScience85
AmitNULLNULL
  • All students appear.
  • If marks exist → show them.
  • If not (like Amit) → show NULL.

Key Difference Table

FeatureINNER JOINLEFT JOIN
Matching RowsShows only rows with matchesShows all rows from left table
Unmatched RowsIgnoredShow as NULL
Use CaseWhen you need only common recordsWhen you need all from left + matches

Real-Life Analogy

  • INNER JOIN → “Invite only couples where both husband AND wife come to the party.”
  • LEFT JOIN → “Invite all husbands. If wife comes, show her; if not, leave it blank.”

Super Simple Memory Trick

INNER JOIN = only matches
LEFT JOIN = all from left + matches from right