Back to SQL Notes
Topic #94

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.

Want to go beyond the notes?

Join Coding Now Tech Institute's SQL course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

INNER JOIN in SQL – FAQs

Quick answers about learning INNER JOIN in SQL in SQL.

This free note from Coding Now Tech Institute explains INNER JOIN in SQL in SQL — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every SQL topic on Coding Now Tech Institute, including INNER JOIN in SQL, is 100% free with no signup required.
With focused practice, most students grasp INNER JOIN in SQL in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now