SQL Topic collection
SQL Joins SQL Topic exercises
Practice reliable INNER, LEFT, FULL, CROSS, self, semi, anti, range, temporal, and many-to-many join patterns.
- Exercises
- 16
- Difficulty
- Beginner to Advanced
What this collection tests
Skills and query patterns
Relationship cardinality, NULL preservation, ON-versus-WHERE semantics, fan-out prevention, and source reconciliation
Curated exercises
Choose an exercise
Work in the live editor where supported. Advanced guided labs state their engine boundary before you open the workspace.
- Exercise 1Easy
Employees with Department Names (INNER JOIN)
Return employee_id, first_name, last_name, and department_name for matched employees, ordered by employee_id.
- Joins
- Sorting
SQLite + PostgreSQL + MySQL + SQL Server live · 1 guided
Open exercise → - Exercise 2Medium
Departments with Their Employees (LEFT JOIN — Empty Groups Visible)
Return every department and its employee details, using NULL employee fields for empty departments.
- Joins
- CASE expressions
- NULL handling
SQLite + PostgreSQL + MySQL live · 2 guided
Open exercise → - Exercise 3Easy
All Departments with Employee Count (LEFT JOIN)
Return every department with its employee_count, ordered by count descending and department_id.
- Joins
- Aggregation
- Sorting
SQLite + PostgreSQL + MySQL + SQL Server live · 1 guided
Open exercise → - Exercise 4Medium
Employee Details — Department + Job (Multi-INNER JOIN)
Chain the employee-to-department and employee-to-job relationships and return the requested profile.
- Joins
- Sorting
SQLite + PostgreSQL + MySQL + SQL Server live · 1 guided
Open exercise → - Exercise 5Medium
Employees with Manager Name (Self-Join + LEFT JOIN)
Return every employee with direct-manager names, leaving manager fields NULL for top-level employees.
- Joins
- NULL handling
- Sorting
SQLite + PostgreSQL + MySQL + SQL Server live · 1 guided
Open exercise → - Exercise 6Easy
USING — Compact Equality Join on Same-Named Columns
Join employees to departments with USING(department_id) and return the requested directory columns.
- Joins
- Sorting
SQLite + PostgreSQL + MySQL live · 2 guided
Open exercise → - Exercise 7Easy
CROSS JOIN — Every Department × Every Job (Cartesian Product)
Generate the intentional Cartesian product of every department and every job.
- Joins
- Sorting
SQLite + PostgreSQL + MySQL + SQL Server live · 1 guided
Open exercise → - Exercise 8Hard
Pairs of Employees with the Same Job Title
Return every unique same-job employee pair with its job title.
- Joins
- Sorting
SQLite + PostgreSQL + MySQL + SQL Server live · 1 guided
Open exercise → - Exercise 9Medium
Keep Unassigned Employees in an As-Of Project Roster
Return every employee and any project assignment active on '2024-07-01'.
- Joins
- Date analysis
- NULL handling
SQLite + PostgreSQL + MySQL + SQL Server live · 1 guided
Open exercise → - Exercise 10Medium
Many-to-Many — Employees ↔ Projects via Junction Table
Follow employees through project_assignments to projects and return one row per assignment.
- Joins
- Sorting
SQLite + PostgreSQL + MySQL + SQL Server live · 1 guided
Open exercise → - Exercise 11Medium
Semi-Join via EXISTS — Departments That Have a Manager
Return each department for which an employee in that department has at least one direct report.
- Joins
- Subqueries
- Filtering
SQLite + PostgreSQL + MySQL + SQL Server live · 1 guided
Open exercise → - Exercise 12Medium
Anti-Join via NOT EXISTS — Employees Without Direct Reports
Return employees for whom no reporting employee exists.
- Joins
- Subqueries
- Filtering
SQLite + PostgreSQL + MySQL + SQL Server live · 1 guided
Open exercise → - Exercise 13Hard
Prevent Fan-Out in an Order Reconciliation
Return each order with item_total, successful_payment_total, and balance_due without multiplying either measure.
- Joins
- Subqueries
- Aggregation
SQLite + PostgreSQL + MySQL + SQL Server live · 1 guided
Open exercise → - Exercise 14Medium
Inequality JOIN — Map Salaries to Pay Bands (ON ... BETWEEN ...)
Join employees to every job range containing their salary and return all matching bands.
- Joins
- Sorting
SQLite + PostgreSQL + MySQL + SQL Server live · 1 guided
Open exercise → - Exercise 15Hard
Temporal "As-Of" JOIN — Salary on a Specific Date
Join employees to salary-history intervals containing the as-of date.
- Joins
- Date analysis
- NULL handling
SQLite + PostgreSQL + MySQL + SQL Server live · 1 guided
Open exercise → - Exercise 16Medium
Reconcile CRM and Billing Accounts with FULL OUTER JOIN
FULL OUTER JOIN CRM and billing accounts by account_code and label each row as Matched, CRM Only, or Billing Only.
- Joins
- CASE expressions
- NULL handling
SQLite + PostgreSQL + MySQL live · 2 guided
Open exercise →
Attempt
Write a query or design from the brief before opening any hints.
Validate
Run it against the included dataset and inspect the output.
Explain
Compare the verified answer and explain each choice aloud.
Learn before practicing SQL Joins
Strengthen your understanding with these targeted learning topics:
Continue practicing
Build the next SQL skill
Self Joins & Hierarchical Queries
Query organization charts, trees, and parent-child relationships.
SQL Subqueries
Practice scalar, derived-table, correlated, EXISTS, NULL-safe anti-subquery, quantified, and row-subquery patterns.
SQL Aggregations
Build reliable SQL metrics from aggregate functions through grain, fan-out, weighted ratios, rollups, percentiles, and approximate counts.
Open the interactive workspace and practice across SQL topics.