INNER JOIN
Returns only rows where there is a match in both tables. Rows without a matching key in either table are excluded.
🗂️ Employees (Table A)
| id | name | dept_id |
|---|---|---|
| 1 | Alice | 10 |
| 2 | Bob | 20 |
| 3 | Carol | 10 |
| 4 | David | 30 |
| 5 | Eve | null |
🏢 Departments (Table B)
| id | dept_name |
|---|---|
| 10 | Engineering |
| 20 | Marketing |
| 40 | Sales |
🔍 Visual Match
📋 Result
| emp_id | name | dept_id | dept_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