What is INNER JOIN?
INNER JOIN combines rows from two tables only when they match.
Simple rule: No match = No show
How INNER JOIN Works
Basic Syntax
SELECT columns
FROM table1
INNER JOIN table2 ON table1.id = table2.foreign_id;Example 1: Students with Orders
SELECT students.name, orders.product
FROM students
INNER JOIN orders ON students.id = orders.student_id;Result: Only John and Mary shown (Peter has no order)
Example 2: Using Aliases
SELECT s.name, o.product, o.amount
FROM students s
INNER JOIN orders o ON s.id = o.student_id;Tip: Use s and o as short names (aliases)
Example 3: With WHERE Filter
SELECT s.name, o.product
FROM students s
INNER JOIN orders o ON s.id = o.student_id
WHERE o.amount > 50;INNER JOIN Rules
- Both must match - Row appears only if match exists in both tables
- No match = hidden - Unmatched rows are excluded
- Order matters - table1 INNER JOIN table2
Quick Comparison
- INNER JOIN → Only matching rows
- LEFT JOIN → All from left + matches
- RIGHT JOIN → All from right + matches
Try It Below
Practice combining two tables with INNER JOIN!
What Comes Next
Next: LEFT JOIN - shows ALL from left table, even without match.