What You'll Master Here
which table, which rows, and which columns?
SQL is how you ask a database questions. This first chapter teaches the basics: what a table is, what one row means, how a query is put together, and how to actually read the answer instead of just trusting it.
We use one small pretend online-shop dataset the whole way through: customers, orders, and the items inside each order. Keeping the data familiar lets you focus on the SQL, not the business.
By the end you will be able to look at a table you have never seen, pick the columns you want, keep only the rows you want, deal with missing values safely, and say in plain words what your query returns.
Before anything fancy, a good query answers three questions: which table, which rows, and which columns?
Most day-to-day SQL is simple: look at a table, check your assumptions, and pull out the rows you need. Getting comfortable with these basics is what makes every later topic (joins, grouping, and so on) easy to learn.
- table
- A grid of data, like a spreadsheet: columns across the top, rows going down.
- row
- One record in a table, e.g. one order. What a row stands for is called its grain.
- column
- One piece of information every row has, like status or created_at. Each column holds one type of value.
- result
- The rows and columns a query gives back. Always take a look at it.
the labels across the top are columns — each holds one kind of value
each line is one row — here, one order
Run a query and what comes back is a result — the same shape: rows and columns.
A customer places many orders; each order contains many items. Notice the grain gets finer left to right.
select -- pick which columns to show
order_id, -- unique id of each order
buyer_id, -- which customer placed it
status, -- paid, pending, refunded, ...
created_at -- when the order was created
from orders -- the table we're reading from
order by created_at desc -- newest orders first
limit 5; -- show only the first 5 rows| order_id | buyer_id | status | created_at |
|---|---|---|---|
| 1044 | 9 | refunded | 2026-01-31 18:04 |
| 1043 | 7 | paid | 2026-01-31 09:22 |
| 1042 | 7 | paid | 2026-01-30 21:10 |
| 1041 | 4 | pending | 2026-01-30 12:48 |
| 1040 | 2 | paid | 2026-01-29 15:31 |
Writing a clever query before inspecting the table. You can produce a polished answer built on the wrong row set or a misread column.
Inspect a small, ordered sample first.
Say the table grain out loud before querying.
Keep the first query readable before making it fancy.
A strong beginner SQL answer is not fancy. It is clear about the table, the filter, the selected columns, and the assumptions being made.
Use the topic menu on the left as a checklist. Each topic is a habit you should be able to demonstrate, not just recognize.
Before optimizing syntax, be able to explain which table, which rows, and which columns your query touches.
