Lesson ยท 6 min
Select columns
Tables hold rows
A database stores data in tables. A table has columns (the kinds of facts) and rows (one record each). This course uses a small table named books:
| id | title | author | genre | year | price |
|---|---|---|---|---|---|
| 1 | The Salt Road | Ines Marchetti | Adventure | 2016 | 14.50 |
| 2 | Paper Lanterns | Haruka Mori | Fantasy | 2019 | 12.00 |
The table has eight books. The two rows above are only the start.
SELECT and FROM
A query says which columns you want and which table they come from.
SELECT genre FROM books;
SELECTlists the columns.FROMnames the table.- The semicolon ends the query.
To get more than one column, separate the names with commas.
SELECT title, year FROM books;
Your turn
Write one query for each task, one after the other. Each query ends with a semicolon. When you press Run, you get one result table for each query. Task 1 checks the first table, and task 2 checks the second.
Tasks
2 to do
Task 1, not checked yet. Write a query that selects only the
titlecolumn from thebookstable.Task 2, not checked yet. Below it, write a second query that selects the
titleandauthorcolumns, in that order.
Task 1 of 2
Write a query that selects only the title column from the books table.