All lessons

Module 1: Start here · Lesson 1.1 · about 20 min

What SQL is and why analysts use it

SQL is the language for asking questions of tables. Run your first queries in the browser and see why almost every data and BI job asks for it.

Key points, meanings and formulas on one page: choose "Save as PDF" in the print box.

Module 1 · about 20 minutes · read first: nothing. You’ll be able to say what SQL is, run your first query, and read a simple query out loud in plain English.

SQL is a short, English-like language for asking questions of tables: you say what answer you want, and the database works out how to find it.

In everyday terms: ordering at a café. You say “a large latte, no sugar”; you don’t walk behind the counter and tell the barista which buttons to press. A query is your order, and the database is the barista.

1. Why this matters

Nearly every company keeps its sales, customers and stock in a database, and the people who answer questions about that data (analysts, BI developers, data scientists) ask those questions in SQL. That is why analyst and BI job ads ask for SQL again and again, and why interviews often include a live SQL test. The good news: you need only a small part of the language to be useful, and you can start in the next two minutes.

2. A database is a set of tables

A table looks like a spreadsheet: a name, a few named columns, and many rows. A database is a set of tables that belong together. In this course you’ll use the database of Northbay Retail, a made-up Canadian store chain, with tables for stores, products, customers and orders.

Here is the smallest table in it, five customers. Press Run.

-- try
SELECT * FROM mini_customers

You’ve just run a query: a question written in SQL. SELECT * means “all the columns”, and FROM mini_customers names the table. The answer comes back as a table too.

3. SQL says what, not how

SQL stands for Structured Query Language (people say “S-Q-L” or “sequel”; both are fine). It is declarative: you describe the answer you want, and the database works out how to find it. You never write loops or open files.

Read this query out loud: “select the name and city from mini customers where the city is Toronto”.

-- try
SELECT name, city
FROM mini_customers
WHERE city = 'Toronto'

Now press Show how it runs and then Play. Watch the steps: FROM fetches all five rows, WHERE fades out the three that aren’t in Toronto, and SELECT keeps only the two columns you asked for. That picture (start with a table, throw rows away, keep some columns) is most of SQL.

Database
A set of tables that belong together, such as all of Northbay's stores, products and orders.
Table
A named grid of rows and columns. Every row has the same columns.
Query
A question written in SQL. It always hands back a table.
SELECT ... FROM ...
"Show me these columns from this table."
WHERE
"Only the rows that pass this test."
Declarative
You describe the result, not the steps to get it.
Physical meaning
A SELECT reads rows, throws away the ones that fail the test, keeps the columns you named and hands you a new, temporary table. The stored table is never changed.

“Running a query changes or moves the data.” A SELECT only reads. It makes a fresh answer table each time and leaves the real table exactly as it was, so you can run it a hundred times without harm. Changing data takes different statements (INSERT, UPDATE, DELETE), which come much later.

Watch it happen, one step at a time (any live box’s Show how it runs button animates the real query in the same way):

FROM mini_customers. Fetch every row.
idnamecity
1AshaToronto
2BenOttawa
3ChenToronto
4DinaHamilton
5EliOttawa
WHERE city = 'Toronto'. Test each row; keep the ones that pass.
idnamecity
1AshaToronto
3ChenToronto
SELECT name, city. Keep only the columns you asked for.
namecity
AshaToronto
ChenToronto
The answer. A new table of 2 rows and 2 columns. mini_customers still has all 5 rows.

Try one yourself. Each time you press New numbers you get a fresh table:

4. Questions a store actually asks

The same few words scale up to real questions. How many orders did Northbay take in 2025?

-- try
SELECT COUNT(*) AS orders_2025
FROM orders
WHERE order_date LIKE '2025%'

How many came through the website and how many in stores? Run it, then change 2025 to 2024 and run again.

-- try
SELECT channel, COUNT(*) AS orders
FROM orders
WHERE order_date LIKE '2025%'
GROUP BY channel

Don’t worry about COUNT, LIKE or GROUP BY yet; each has its own lesson. Notice instead that the query reads almost like the question.

Maths and principle

Principle: a table is a relation: a set of rows, where every row has the same named columns. A query is a function that takes relations in and gives one relation back. That is why you can feed the answer of one query into another.

Equation: answer = q(tables). For the Toronto query, q keeps the rows where city = ‘Toronto’ (written σ, selection) and then keeps two columns (written π, projection): answer = πname, city( σcity = ‘Toronto’( mini_customers ) ).

Analogy: a library catalogue. You ask “all books by this author, title only”, and the librarian decides which shelf to walk to first. It breaks down a little because real tables can hold the same row twice, which a pure set cannot (SQL tables are bags, more on that in Module 3).

Try it: what is πcity( mini_customers ) as a set? (Toronto, Ottawa, Hamilton: three values, because a set keeps each once.)

5. Worked example

Question: what did order 1010 contain, and what was it worth?

-- try
SELECT order_id, product_id, quantity, unit_price
FROM order_items
WHERE order_id = 1010
  1. The order has 3 lines: product 47 (Laundry detergent, 1 × $14.99), product 11 (Bagels 6 pack, 4 × $4.49) and product 55 (Art kit, 1 × $24.99).
  2. Line values: 14.99, 4 × 4.49 = 17.96, and 24.99.
  3. Order value: 14.99 + 17.96 + 24.99 = $57.94.

SQL can do the sum for you:

-- try
SELECT SUM(quantity * unit_price) AS order_value
FROM order_items
WHERE order_id = 1010

6. SQLite, SQL Server, PostgreSQL

There is one SQL standard and many databases that speak it with small accents. This course runs SQLite in your browser, so nothing is installed and nothing you type leaves your device. Almost everything you learn works the same in SQL Server, PostgreSQL, MySQL and BigQuery; where it differs, the lesson says so in one line.

7. Practice

-- exercise: Show every row and column of the mini_orders table.
-- hint: SELECT * FROM the table's name.
SELECT * FROM mini_customers
-- answer:
SELECT * FROM mini_orders
-- exercise: List the name of every mini customer who lives in Ottawa.
-- hint: WHERE city = 'Ottawa'. Text goes in single quotes.
SELECT name
FROM mini_customers
-- answer:
SELECT name
FROM mini_customers
WHERE city = 'Ottawa'
-- exercise: How many orders did Northbay take in 2024?
-- hint: Copy the 2025 query from section 4 and change the year.
SELECT COUNT(*) AS orders
FROM orders
-- answer:
SELECT COUNT(*) AS orders
FROM orders
WHERE order_date LIKE '2024%'

Try it on your own data: load a CSV into [[sql-playground]] and query it the same way.

  • SQL is the language for asking questions of tables; almost every data and BI job uses it.
  • A database is a set of tables; a table is rows and columns.
  • SQL is declarative: you say what you want, the database plans how.
  • Every SELECT hands back a table and never changes the stored data.
  • FROM picks the table, WHERE keeps rows, SELECT keeps columns.

New words: database, table, query, declarative, relation, SQLite.

Check yourself

1What do you tell the database when you write SQL?
2What does a SELECT query hand back?
3Does running SELECT * FROM customers change the customers table?

Sources

Your ticks stay in this browser. Save them as a file on the course home.

Updated 2026-11-22. Northbay Retail is a made-up company; its data is generated in your browser. Queries run on your device and nothing you type is sent anywhere.