Coding Now – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 9667708830
Back to SQL Notes
Topic #508

INNER JOIN vs LEFT JOIN

Reference Tables Used in This Section

Every join note below uses these same two tables, so you can see exactly how each join type treats the same data differently.

employees

idnamedepartment_id
1Aman1
2Riya2
3Karan1
4NehaNULL

departments

iddepartment_name
1Engineering
2Marketing
3Sales

Notice: Neha has no department (department_id is NULL), and Sales has no employees at all. These two "unmatched" rows are what make the differences between join types visible.

The Core Difference

INNER JOINLEFT JOIN
ReturnsOnly matched rowsAll rows from the left table, matched or not
Unmatched left rowsExcludedIncluded, with NULLs for the right table's columns
Row count vs left tableLess than or equal toAlways greater than or equal to

Side-by-Side Example

-- INNER JOIN
SELECT e.name, d.department_name
FROM employees e
INNER JOIN departments d ON e.department_id = d.id;
-- 3 rows — Neha excluded (no department)

-- LEFT JOIN
SELECT e.name, d.department_name
FROM employees e
LEFT JOIN departments d ON e.department_id = d.id;
-- 4 rows — Neha included, with NULL department_name

How to Decide Which One You Need

  • Ask: "Do rows without a match still matter for this report?"
  • If no — an employee with no department is irrelevant to what you're building — use INNER JOIN.
  • If yes — you need to see every employee regardless, or specifically want to find the ones without a match — use LEFT JOIN.

Practical Use Case

A payroll report that should only include employees with a valid, assigned department: INNER JOIN. An HR audit report meant to catch employees missing a department assignment: LEFT JOIN with WHERE department_id IS NULL.

Common Mistake

Defaulting to INNER JOIN out of habit and silently dropping rows that a report actually needed to include — a very common, hard-to-notice bug, since the query runs fine and just returns fewer rows than expected with no error.

Interview Relevance

This comparison is asked constantly, often phrased as a scenario rather than a direct definition question — e.g. "Why does my report have fewer employees than the total employee count?" (Answer: an INNER JOIN is silently dropping unmatched rows.)

Practice Question

A report using INNER JOIN between employees and departments shows 3 rows, but the company has 4 employees. Explain why, and write the fix.

Related SQL Notes

Want to go beyond the notes?

Join CodingNow's SQL course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →