2. Designing Tables & Combining Data

Practice Lab: Real SQL Query Drills

Practice writing SELECT, WHERE, IS NULL, LEFT JOIN, GROUP BY, HAVING, CASE WHEN, and Window Functions against a live relational database in your browser.

3 min readUpdated 2026-11-30
In This Lesson
  • Write filtered SELECT queries with sorting and NULL checks
  • Combine multiple tables with LEFT JOIN to find unmatched rows
  • Calculate grouped revenue, HAVING filters, and window rankings on live data

Every SQL playground below runs on a real SQLite engine with pre-loaded tables: courses, students, enrollments, customers, products, orders, and order_items.

Write your query inside each editor, click Run Code, and compare with the sample solution!

Recall SQL Clause Execution Order

Filter raw rows first with WHERE, aggregate with GROUP BY, filter finished groups with HAVING, and finally sort with ORDER BY.

Drill 1: Students Missing a Phone Number

Query students (id, full_name, email) to find only students whose phone is missing (NULL), sorted alphabetically by full_name.

SQL (SQLite)Drill 1: Find Missing Phone Numbers
Output

Click “Run Code” to execute this snippet right in your browser.

Drill 2: Customers Who Have Never Ordered

Use customers (id, name, city) and LEFT JOIN orders to list every customer who has 0 orders (o.id IS NULL).

SQL (SQLite)Drill 2: Inactive Customers (LEFT JOIN)
Output

Click “Run Code” to execute this snippet right in your browser.

Drill 3: Paid Revenue Per Product Category

Join products, order_items, and orders (WHERE o.status = 'paid') to calculate total units sold and revenue (SUM(oi.quantity * oi.unit_price)) grouped by p.category.

SQL (SQLite)Drill 3: Category Revenue Report
Output

Click “Run Code” to execute this snippet right in your browser.

Drill 4: High-Value Customers (GROUP BY + HAVING)

Find only customers whose total paid order spend is strictly greater than $100. Remember: WHERE filters orders to 'paid' before grouping, while HAVING filters each customer's total after grouping!

SQL (SQLite)Drill 4: High-Value Customers with HAVING
Output

Click “Run Code” to execute this snippet right in your browser.

Drill 5: Label Products by Tier (CASE WHEN)

Classify every row in products as 'Premium' (price >= 50) or 'Standard' (price < 50) using CASE WHEN.

SQL (SQLite)Drill 5: Pricing Tier Classification
Output

Click “Run Code” to execute this snippet right in your browser.

SQL Practice Lab Progress

0/5 done