Learn SQL from scratch: queries, tables and real examples
What a relational database is, the SQL queries you'll use most at work and a plan to learn PostgreSQL for free from scratch.
Almost every app stores its information in a database. SQL is one of the most requested skills: developers, data analysts and testers all use it.
What is a relational database?
Picture spreadsheets linked to each other. Each table stores one kind of thing (customers, orders, products) and each row is a record. Tables are related through keys: an order stores the id of the customer who placed it.
The queries you'll use most
-- Read: the 10 most recent orders
SELECT id, customer_id, total
FROM orders
ORDER BY created_at DESC
LIMIT 10;
-- Filter and group: how much each customer spent this year
SELECT customer_id, SUM(total) AS spent
FROM orders
WHERE created_at >= '2026-01-01'
GROUP BY customer_id;
-- Join tables: the customer name for each order
SELECT o.id, c.name, o.total
FROM orders o
JOIN customers c ON c.id = o.customer_id;
With SELECT, WHERE, ORDER BY, GROUP BY and JOIN you can answer most everyday questions.
Recommended learning order
- Basic queries:
SELECT,WHERE,ORDER BY,LIMIT. - Aggregations:
COUNT,SUM,AVG,GROUP BY,HAVING. - JOINs: combining tables without duplicating data.
- Design: tables, data types, primary and foreign keys, normalization.
- Indexes: why a query is slow and how to speed it up.
- Transactions: making sure a transfer never ends up half done.
How to practice
Install PostgreSQL (free) or use an online playground, load a sample database and ask real questions: which product sells the most? which customers haven't bought in 3 months?
Next step
Codea's free Databases Jr route teaches SQL with PostgreSQL plus an introduction to MongoDB, with challenges on real data. Route content is in Spanish.
Videos, hands-on challenges, quizzes and teacher reviews (route content is in Spanish).