Home / Learn Secure SQL / JOINs: Combining Tables
JOINs: Combining Tables
INNER, LEFT, and why the difference matters for security logic too.
Bottom lineINNER, LEFT, and why the difference matters for security logic too.
Breaking it down
Definition
A JOIN combines rows from two tables based on a matching column, usually a foreign key.
Why you need this
Real data is normalized across many tables; almost every meaningful query joins at least two of them.
How it works
INNER JOIN keeps only matching rows on both sides; LEFT JOIN keeps every row from the left table even with no match.
Where you'll see this
- Web application code review
- Backend development
- Database administration
Join users and ordersSQL: edit and run
Chi has no "paid" orders shown separately; try changing to LEFT JOIN FROM users u LEFT JOIN orders o to see every user including ones with no orders.
Test what you just read
1. LEFT JOIN keeps...
Unmatched rows become NULL on the right.