All guides

SQL exercises for beginners, solved and explained (runnable in your browser)

The best way to learn SQL is not memorising syntax: it is querying a real table and looking at what comes out. Every exercise on this page runs against this impiegati (employees) table, and you can run and edit them right here with "Try it":

idnome (name)reparto (dept)stipendio (salary)
1AnnaVendite2500
2LucaIT3200
3MarcoIT2800
4SaraVendite2700
5ElenaHR2400

Exercise 1 — Read everything

Show every employee, every column.

SELECT * FROM impiegati;

SELECT picks the columns (* = all of them), FROM says which table to read. This is the skeleton of every query.

Exercise 2 — Pick your columns

Show only name and salary.

SELECT nome, stipendio FROM impiegati;

Real-world tables have dozens of columns: asking only for what you need keeps queries clearer (and faster).

Exercise 3 — Filter rows

Who works in the IT department?

SELECT nome, stipendio
FROM impiegati
WHERE reparto = 'IT';

WHERE filters rows: only those matching the condition pass. Note the single quotes around 'IT' — that is how strings are written in SQL.

Exercise 4 — Sort

Everyone, highest paid first.

SELECT nome, stipendio
FROM impiegati
ORDER BY stipendio DESC;

ORDER BY sorts the result; DESC means descending (without it, ascending). Try removing DESC and re-running.

Exercise 5 — Count and average

How many employees are there, and what is the average salary?

SELECT COUNT(*), AVG(stipendio)
FROM impiegati;

COUNT, AVG, SUM, MIN, MAX are aggregate functions: they squeeze many rows into a single number. They are the heart of every report.

Exercise 6 — Group (the level-up)

Average salary per department.

SELECT reparto, AVG(stipendio) AS media
FROM impiegati
GROUP BY reparto
ORDER BY media DESC;

GROUP BY splits rows into groups (one per department) and applies the aggregation to each group. When this feels natural, you understand 70% of the SQL actually used at work.

What next?

If you enjoyed these six exercises, the full SQL path starts here and goes all the way to JOINs, subqueries, window functions, indexes and transactions — 13 chapters and 100+ exercises, all runnable in the browser like these. The first chapters are free.

Learn by doing, not just reading

Zero-to-advanced paths with exercises you write and run in the browser. The first chapters are free.

SQL exercises for beginners, solved and explained (runnable in your browser) — LevelUpCode