Class 34 of 58 • Relational Joins & Set Operations

SQL INNER JOIN: Matching Records Across Multiple Tables

The INNER JOIN is the most common join in database computing. It queries records from two or more tables and returns only the rows that satisfy the join condition in both tables. Any unmatched records on either side are completely omitted from the result set.


Standard INNER JOIN Syntax

SELECT a.column1, b.column2
FROM table_a a
INNER JOIN table_b b ON a.key = b.key;

Hands-on Query: Students & Department Names

-- Join students and departments on dept_id
SELECT 
    s.student_id,
    s.first_name,
    d.dept_name,
    s.gpa
FROM students s
INNER JOIN departments d ON s.dept_id = d.dept_id;
student_id first_name dept_name gpa
1 Aman Engineering 3.85
2 Pooja Business 3.92
3 Rohan Engineering 3.75
Notice What is Missing:
1. Vikram (student with NULL dept_id) is excluded because NULL matches nothing.
2. Arts department (dept_id 30 with no students) is excluded because no student references it.
To retain unmatched rows, we use OUTER JOINS!

Next, let us learn how to keep all rows from the primary table using SQL LEFT OUTER JOIN!


Frequently Asked Questions (FAQ)

An INNER JOIN excludes any row from Table A that has no match in Table B, as well as any row from Table B that has no match in Table A. Only mutual matches are included.

They are completely identical! In standard ANSI SQL, writing 'JOIN' defaults to an INNER JOIN.

Yes! You can chain multiple JOIN ... ON clauses together to connect three, four, or more related tables (e.g., students -> enrollments -> courses -> professors).

Next Step in Your SQL Database Learning Path:

Proceed to the next class in sequence to build production mastery of relational database architecture.

Continue to Class 35: LEFT JOIN → Previous: ← Joins Overview | Full Syllabus


Related SQL Masterclass Lessons & Recommended Next Topics

Joins Architecture Overview →

Relational algebra principles of inner and outer joins.

LEFT OUTER JOIN →

Comparing inner join with outer joins that preserve unmatched rows.

CROSS JOIN & Self Join →

Joining tables without ON clauses and self-referencing joins.

Indexing Foreign Keys →

How B-tree indexes turn O(N^2) joins into O(N log N) speed.

Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Reddit

You may also like this!