
SQL (Structured Query Language) is the language used to read and change data in relational databases, which store information in tables of rows and columns. It powers banks, online shops and apps, and it is a core skill for analysts and developers. The good news is that the core of SQL is small. With one to two hours a day, you can learn enough in a week to answer real questions about real data.
In 1970 Edgar F. Codd at IBM described the relational model, and in the following years his colleagues Donald Chamberlin and Raymond Boyce designed a language for it called SEQUEL, later renamed SQL. It became an ANSI standard in 1986 and is still the common language of databases such as PostgreSQL, MySQL, SQLite, SQL Server and Oracle. Dialects differ, but the basics work almost everywhere.
Start with SELECT and FROM: SELECT name, price FROM products; returns two columns from the table. Add WHERE to filter rows, for example WHERE price > 20 AND category = 'books', and ORDER BY price DESC to sort. Learn LIMIT, DISTINCT, IN, BETWEEN and LIKE for text patterns. Write twenty small queries today. Avoid SELECT * in real work: naming the columns you need is clearer and faster.
Aggregate functions summarise many rows into one value: COUNT, SUM, AVG, MIN and MAX. Combined with GROUP BY, they answer questions like "how many orders per country?". Use HAVING to filter groups after aggregation, because WHERE filters rows before it. Learn the logical order in which a query runs: FROM, WHERE, GROUP BY, HAVING, SELECT, ORDER BY. That is why a column alias defined in SELECT usually cannot be used in WHERE.
Relational databases split data into several tables linked by keys. A primary key uniquely identifies each row, and a foreign key points to a row in another table. Joins put the pieces back together:
Practise with questions such as "which customers have never placed an order?", solved with a LEFT JOIN and WHERE orders.id IS NULL.
A subquery is a query inside another query, for example finding products priced above the average with WHERE price > (SELECT AVG(price) FROM products). For longer logic, use a common table expression: WITH gives a temporary name to a result, so you can build a query step by step and read it from top to bottom. Also learn CASE WHEN to label values, such as small, medium or large orders.
Create a table with CREATE TABLE, choosing data types and constraints such as NOT NULL, UNIQUE and PRIMARY KEY. Add rows with INSERT, change them with UPDATE and remove them with DELETE.
Be careful: an UPDATE or DELETE without a WHERE clause affects every row in the table. Run the matching SELECT first to see which rows you will change, and wrap risky changes in a transaction with BEGIN, so you can ROLLBACK if something looks wrong or COMMIT if it is right. Never practise on a production database.
Window functions calculate across related rows without collapsing them into groups. ROW_NUMBER(), RANK() and running totals with SUM(...) OVER (PARTITION BY ... ORDER BY ...) answer questions like "the top three products in each category". Then learn what an index is: a structure that helps the database find rows quickly, like the index at the back of a book. Use EXPLAIN to see how a query is executed.
Pick a dataset you find interesting, such as sports results or public transport data. Import it, write down ten questions, and answer each with a query. Save the queries in a file with short comments starting with --. If you want to go further, connect SQL to a programming language; if you learn Python, libraries such as sqlite3 and pandas make this easy.
One week gives you a solid base, not expertise. Keep writing a few queries every day, and revisit tricky topics such as joins and window functions with spaced repetition so they stick.
Grade 10 Math: Functions and Reasoning - Quiz
1170 questions