Home/Blog/SQL JOINs Explained with Real Examples
SQL BasicsJOINs

SQL JOINs Explained with Real Examples

SQLab Team·2025-01-10·8 min read

JOINs are the foundation of relational SQL. Without them, you'd need multiple queries to combine data from different tables. This guide explains every JOIN type clearly, with examples you can run in the SQLab playground.

Practice these queries in SQLab →
Real SQLite engine · 8 tables · No signup needed
Open Playground

INNER JOIN

What is INNER JOIN?

Returns only rows where there is a match in BOTH tables. Rows with no match in either table are excluded.

Example

SELECT u.first_name, o.total, o.status
FROM users u
INNER JOIN orders o ON o.user_id = u.id
LIMIT 10;

-- Only users WHO HAVE orders are returned.

LEFT JOIN

What is LEFT JOIN?

Returns ALL rows from the left table, and matching rows from the right. If no match exists, right-table columns are NULL. Essential when you want to include records even without related data.

Example

SELECT u.first_name, COUNT(o.id) AS order_count
FROM users u
LEFT JOIN orders o ON o.user_id = u.id
GROUP BY u.id
ORDER BY order_count DESC;

-- All users appear, even those with 0 orders.

Joining Multiple Tables

3-table JOIN example

SELECT u.first_name, p.name AS product, oi.quantity
FROM users u
JOIN orders o ON o.user_id = u.id
JOIN order_items oi ON oi.order_id = o.id
JOIN products p ON p.id = oi.product_id
LIMIT 20;

Pro tip

Always use table aliases (u, o, p) when joining multiple tables. Always specify the JOIN condition in ON — never use implicit comma joins (FROM a, b WHERE a.id = b.id is old syntax and error-prone).

Ready to practice?

Run all the queries from this article in our free SQL playground.

Open SQL Playground →

Related Articles

Top 30 SQL Interview Questions (2025)12 min readGROUP BY vs HAVING: What's the Difference?5 min readSQL Window Functions: A Complete Guide10 min read