Open it first
Press the button under the first example. Planche opens in a new browser tab with the shop database already loaded. The database file stays in the page, so changes do not affect anyone else. To start over, reload the sample from the welcome screen.
A table is a grid
Run this one. It asks for everything in the table called categories.
1
SELECT * FROM categories;
Result — first 5 of 33 rows
| id | name | description | parent_id | sort_order | is_active |
|---|---|---|---|---|---|
| 1 | Electronics | Electronics and related products | NULL | 0 | 1 |
| 2 | Laptops | Laptops in Electronics | 1 | 1 | 1 |
| 3 | Phones | Phones in Electronics | 1 | 2 | 1 |
| 4 | Tablets | Tablets in Electronics | 1 | 3 | 1 |
| 5 | Audio | Audio in Electronics | 1 | 4 | 1 |
Opens Planche in a separate browser tab, with the sample database loaded and this query ready. Every example on the page reuses that tab, and nothing runs until you press F9.
The result is a grid: that is a table. Three terms describe it:
- A column is one of the headings across the top —
id,name,description. Every entry in the table has these same six, and the names are what you will type in queries. - A row is one line down the grid, and it is one thing. Here, one row is one category. There are 33 rows, so the shop has 33 categories.
- A cell is where a row and a column meet — one value, like the name of one particular category.
Every table in this database is that same shape. products has one row per product, orders one row per order, customers one row per customer. What changes is which columns each one has.
Some cells are empty, and that has a name
2
SELECT id, name, parent_id
FROM categories
LIMIT 8;
Result — first 5 of 8 rows
| id | name | parent_id |
|---|---|---|
| 1 | Electronics | NULL |
| 2 | Laptops | 1 |
| 3 | Phones | 1 |
| 4 | Tablets | 1 |
| 5 | Audio | 1 |
Look at parent_id. Some rows have a number and some are marked NULL. That column says which category this one sits inside — Laptops sits inside Electronics — and the top-level categories sit inside nothing, so there is nothing to put there.
NULL means "no value here". It is worth learning as its own idea rather than as a kind of zero, because it is not one:
- NULL is not
0. Zero is a number you measured; NULL is a measurement you do not have. - NULL is not an empty piece of text either. A customer whose name is recorded as blank is different from a customer whose name was never recorded.
NULL follows its own comparison rules, covered in the third lesson. For now, treat it as a missing or unknown value rather than an empty cell.
Every row has a number of its own
The first column here is id, and it is a number that belongs to exactly one row and is never reused. That is the row's primary key — how anything else refers to this row without depending on its name, which somebody might change.
Almost every table you meet has one, usually called id.
Why 23 tables and not one
A shop could use one enormous table, with a customer's name, address, products, and prices repeated on every order row. That would make updates unreliable: when a customer moves, every past order would need the same change, and missed rows would leave conflicting data behind.
Instead each kind of thing gets its own table, and rows point at each other by primary key. products.category_id holds a categories.id. orders.customer_id holds a customers.id. A column that points at another table's row is a foreign key, and following one is what the fourth lesson calls a join.
That is also why you need somewhere to look up which columns a table has. The sample database page lists every table, every column, and which column points at which table. Keep it open in another tab — even people who write SQL every day keep the schema next to them.
A query is a question, and the answer is a table too
One row, one column, one number. That is still a table, just a very small one — which is the whole idea behind SQL: you send a question, and what comes back always has the same rectangular shape, whether it is 400 rows or one.
Notice that this answer is nowhere in the database. Nothing stores the number 400; the database counted the rows when you asked. Most useful queries are like that — they compute an answer rather than look one up.
Running one yourself
In the editor at the top of the workspace, type or edit a query and press F9 to run it — or Ctrl / ⌘ + Enter to run just the statement your cursor is in. The result appears in the grid below, and the row count sits at the bottom.
The panel on the left is the same database as a tree: expand main, then Tables, and double-click any table to see its rows without writing anything at all. That is often the fastest way to find out what is in a table before you query it.
Every example on these pages opens in its own tab, so you can change one, run it, and change it back without losing your place.
When it goes wrong
It will, and the messages are short and literal. Misspell a column and you get:
no such column: naem
Read the end of the message first — it usually names the exact thing the database could not find. The three that account for most early errors are a misspelled column, a column that lives in a different table than you thought, and a missing quote around text (SQL wants 'paid', with single quotes; double quotes mean something else).
An error means nothing ran. The statement is rejected whole, so a query that fails has changed nothing.
What next
You know what a table, a row, a column and a NULL are, and you can run a query and read the result. The next lesson is the four clauses that nearly every query is built from.