1 · Read the data · 12 MIN
Read a table before writing a query
A table holds rows of the same shape; a result is another table.
The practice database contains learners. Each row represents one learner and each column has a role: id identifies the row, name is text, city may be unknown and points is an integer. SELECT chooses the columns you want to see; FROM names the source table. ORDER BY defines a repeatable order. SQL is not a loop you write for every row: you describe the result and the database finds it. The setup below is already loaded when you run the lesson.
Keep the source rows visible. Predict which rows and columns will remain after each operation.
Before you start
No installation. The tables below are loaded automatically for every run; edits do not touch the CodingNeed account database.
New words, explained
- row
- One record, such as one learner.
- column
- One named property shared by records.
- primaryKey
- A value uniquely identifying each row.
Follow the example step by step
- Inspect the four source rows in the table preview.
- Find the two selected column names.
- Read FROM learners as the source, then ORDER BY id as the result order.
- Notice that output rows contain only the selected columns.
| id | name | city | points |
|---|---|---|---|
| 1 | Ada | Delhi | 20 |
| 2 | Lin | NULL (unknown) | 0 |
| 3 | Grace | Delhi | 35 |
| 4 | Sam | Pune | 20 |
| learner_id | course |
|---|---|
| 1 | React |
| 1 | SQL |
| 3 | SQL |
You are ready to move on when: Return only the name column from learners, ordered by id. Do not include id in the output.
Read the example
SELECT id, name FROM learners ORDER BY id;
Check the expected output
[[1,"Ada"],[2,"Lin"],[3,"Grace"],[4,"Sam"]]
Your challenge
Return only the name column from learners, ordered by id. Do not include id in the output.
Common trap
SELECT * returns every column; use an explicit list when the result contract names particular columns.
Further reading: SQLite SELECT reference
Next lesson: Keep matching rows with WHERE →