How this course works
This site runs a real PostgreSQL 16 server inside your browser tab. Every code box is editable, and the Run button (or Ctrl/⌘ + Enter) sends your SQL to that server and shows exactly what PostgreSQL returns, including its error messages.
You work with one small shop database called shopco. It has six tables: departments, employees, customers, products, orders and order_items. Open Tables in the top bar at any time to see their columns. The data is deliberately imperfect (a customer with no city, a product nobody bought, an employee with no department) so you can see how NULLs and joins behave in real life.
Changes you make last while you move between lessons, until you reload the page or press Reset database. So go ahead and delete things; you can always put them back.
How each lesson is built
- Concept: what the feature is and when you need it.
- Syntax: the general shape of the command.
- Examples: runnable queries, each followed by a line-by-line explanation.
- Exercises: write your own query and press Check answer. The checker compares your result with the expected result, so any correct query passes.
Installing PostgreSQL on your own machine
When you want to practise outside this site: on Windows and macOS use the installer from postgresql.org (or Postgres.app on Mac); on Ubuntu run sudo apt install postgresql; or use Docker with docker run -e POSTGRES_PASSWORD=secret -p 5432:5432 postgres:16. Connect with the command-line client psql -h localhost -U postgres, or a GUI such as pgAdmin or DBeaver. Everything you learn here works the same there.
Syntax
SELECT what_you_want FROM which_table;
Examples
Edit the code and run it. Output is printed the way psql prints it.
1.1Your first query
SELECT 'Hello, PostgreSQL!' AS greeting;SELECT asks PostgreSQL to return values. Here there is no table at all, just a text value in single quotes. AS greeting names the output column. Every statement ends with a semicolon.
1.2Look at a table
SELECT *
FROM products
LIMIT 5;SELECT *means “all columns”.FROM productspicks the table.LIMIT 5returns only the first five rows, which is a good habit when exploring a table you don’t know yet.
Exercises
Write a query and check it. Any query that returns the right rows passes.
Exercise 1.1
departments table.Hint
Use SELECT * with FROM.
Solution
SELECT * FROM departments;Questions
Is this PostgreSQL course free?
Yes. All 27 lessons, the exercises and the playground are free, with no sign-up.
Do I need to install PostgreSQL?
No. A real PostgreSQL 16 server runs inside your browser using WebAssembly, so every example runs instantly. When you are ready, the first lesson explains how to install PostgreSQL on Windows, macOS, Linux or Docker.
Who is this course for?
Beginners who have never written SQL, and developers who know basic SQL and want PostgreSQL features such as window functions, JSONB, indexes, PL/pgSQL and row-level security.
How are the exercises checked?
Your query runs on the live database and its result is compared with the expected result, so any correct query passes, not only one exact answer.
Is my data saved?
Changes to the practice database last while you move between lessons and are cleared when you reload the page or press Reset database. Your lesson progress is remembered in your browser.