INNER JOIN

Returns only rows where there is a match in both tables. Rows without a matching key in either table are excluded.

Most common Matching rows only

🗂️ Employees (Table A)

idnamedept_id
1Alice10
2Bob20
3Carol10
4David30
5Evenull

🏢 Departments (Table B)

iddept_name
10Engineering
20Marketing
40Sales

🔍 Visual Match

A only Match B only 2 rows 3 rows 1 row
Included from A Included from B Excluded

📋 Result

emp_idnamedept_iddept_name

📝 Generated SQL

💡 When to use INNER JOIN

Use when you only want rows that exist in both tables. Great for lookups where missing data should be silently dropped.

⚠️ Common mistake

Forgetting that NULL values never match in JOINs. If dept_id is NULL, that row disappears from an INNER JOIN result.

🚀 Performance tip

Ensure the joined columns are indexed. A missing index on dept_id turns a fast merge join into a slow nested loop.

📚 More resources

Try our SQL INSERT Generator or Schema Diff to compare database schemas across environments.

Compare real database schemas in seconds

SchemaLens diffs PostgreSQL, MySQL, SQLite, SQL Server, and Oracle schemas. Generate migration scripts automatically.

Open Schema Diff