Skip to main content
SQL Practice

Practice exercises for SQL beginners

Reading about SQL is not enough. The only way to actually learn it is to write queries — make mistakes, debug them, and try again. These exercises give you structured problems to work through, from your first SELECT all the way to subqueries.

Before you start

You need somewhere to run queries. Both of these are free and require no setup:

  • BigQuery Sandbox — Google's cloud SQL environment. Free tier, no credit card needed. Best for learning industry-standard SQL.
  • SQLiteOnline.com — Runs entirely in your browser. Paste in the CREATE TABLE statements and start querying immediately. Great for quick practice.

Tip: Try writing the query yourself before revealing the answer. Even an incorrect attempt will teach you more than reading the solution.

Beginner5 exercises

1

Select all columns

SELECT *

Write a query to return all rows and columns from the orders table.

Show answer

Try writing the query yourself before revealing the answer

SELECT * FROM orders;
2

Select specific columns

SELECT columns

Return only the customer_name and order_date from the orders table.

Show answer

Try writing the query yourself before revealing the answer

SELECT customer_name, order_date FROM orders;
3

Filter with WHERE

WHERE

Return all orders where the order_status is "completed".

Show answer

Try writing the query yourself before revealing the answer

SELECT * FROM orders WHERE order_status = 'completed';
4

Count rows

COUNT

How many orders are in the orders table?

Show answer

Try writing the query yourself before revealing the answer

SELECT COUNT(*) FROM orders;
5

Sort results

ORDER BY

Return all orders sorted by order_date from newest to oldest.

Show answer

Try writing the query yourself before revealing the answer

SELECT * FROM orders ORDER BY order_date DESC;

Intermediate5 exercises

6

Group and count

GROUP BY + COUNT

How many orders does each customer have? Return customer_name and order count.

Show answer

Try writing the query yourself before revealing the answer

SELECT customer_name, COUNT(*) as order_count FROM orders GROUP BY customer_name;
7

Average value

AVG + GROUP BY

What is the average order value per customer?

Show answer

Try writing the query yourself before revealing the answer

SELECT customer_name, AVG(order_value) as avg_value FROM orders GROUP BY customer_name;
8

Filter groups with HAVING

HAVING

Return customers who have placed more than 5 orders.

Show answer

Try writing the query yourself before revealing the answer

SELECT customer_name, COUNT(*) as order_count FROM orders GROUP BY customer_name HAVING COUNT(*) > 5;
9

JOIN two tables

INNER JOIN

Return the order_id and customer email for all orders. Orders table has customer_id, customers table has customer_id and email.

Show answer

Try writing the query yourself before revealing the answer

SELECT o.order_id, c.email FROM orders o INNER JOIN customers c ON o.customer_id = c.customer_id;
10

LEFT JOIN

LEFT JOIN

Return all customers and their total order count, including customers with zero orders.

Show answer

Try writing the query yourself before revealing the answer

SELECT c.customer_name, COUNT(o.order_id) as order_count FROM customers c LEFT JOIN orders o ON c.customer_id = o.customer_id GROUP BY c.customer_name;

Advanced2 exercises

11

Subquery

Subquery

Return all orders with a value above the average order value.

Show answer

Try writing the query yourself before revealing the answer

SELECT * FROM orders WHERE order_value > (SELECT AVG(order_value) FROM orders);
12

CASE WHEN

CASE WHEN

Add a column categorizing each order as Low (<50), Medium (50-200), or High (>200) based on order_value.

Show answer

Try writing the query yourself before revealing the answer

SELECT *, CASE WHEN order_value < 50 THEN 'Low' WHEN order_value <= 200 THEN 'Medium' ELSE 'High' END as value_tier FROM orders;

Ready to go further?

Build on these skills in the Data Analyst track — quiz-gated lessons that take you from SQL basics to real analyst workflows.

Build on these skills in the Data Analyst track