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 #502

INNER JOIN in SQL

INNER JOIN returns only the rows that have a match in both tables. It's the default, most commonly used join type.

employees departments

🔵 Shaded = only the overlap is returned — rows with a match on both sides.

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.

Syntax

SELECT columns
FROM table1
INNER JOIN table2 ON table1.column = table2.column;

INNER is optional in most databases — JOIN alone defaults to an inner join.

Example

SELECT e.name, d.department_name
FROM employees e
INNER JOIN departments d ON e.department_id = d.id;

Expected Output:

namedepartment_name
AmanEngineering
RiyaMarketing
KaranEngineering

3 rows, not 4 and not 3+3. Neha is excluded (her department_id is NULL — nothing to match). Sales is excluded (no employee has department_id = 3).

Practical Use Case

Any report where a row without a match is meaningless — e.g. "list employees and their department names." An employee with no department wouldn't have anything sensible to show in that column anyway, so excluding them is often correct.

Common Mistakes

  • Using INNER JOIN when you actually need unmatched rows too (e.g. "show me ALL employees, including those without a department") — that calls for LEFT JOIN instead
  • Joining on a column with mismatched data types (e.g. an INT ID vs a VARCHAR ID) — this can silently return zero rows or force an expensive implicit conversion
  • An unintentional many-to-many join (join column not unique on either side) silently multiplying row counts — always sanity-check row counts after a join

Interview Relevance

Q: "If employees has 4 rows and departments has 3, and you INNER JOIN them, how many rows can you get?" Trick question — it depends entirely on how many rows actually match on the join condition, not on the table sizes. In this example: exactly 3.

Practice Question

Using the reference tables, write the INNER JOIN query and confirm your result matches the 3-row output above.

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 →