SQL

Lesson 1 of 10

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;
  • SELECT lists the columns.
  • FROM names 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

  1. Task 1, not checked yet. Write a query that selects only the title column from the books table.

  2. Task 2, not checked yet. Below it, write a second query that selects the title and author columns, in that order.

Task 1 of 2

Write a query that selects only the title column from the books table.

All tasks

query.sql

Ctrl+Enter runs your code. Ctrl+Shift+Enter checks it. Press Esc, then Tab, to leave the editor.

Output

Press Run to see your result

Your output shows here. Press Run to try your code.