Lesson 1 of 12 · 5 min

Your first query

A database stores data in tables. A table is like a spreadsheet: each row is one thing (a product, a customer) and each column is one fact about it (name, price).

This lesson's practice shop has a products table:

id name category price
1 Laptop Electronics 650.00
2 Phone Electronics 220.00
3 Headphones Electronics 45.00
...

You get data out with SQL (Structured Query Language), using a SELECT statement:

SELECT * FROM products;
  • SELECT says which columns you want. * means "all of them".
  • FROM says which table to read.
  • The semicolon ends the statement.

Usually you only want some columns. List them, separated by commas:

SELECT name, category FROM products;

SQL keywords are not case-sensitive (select works too), but writing them in capitals makes queries easier to read.

The database runs in your browser (SQLite). Press Run ▶ to see the result table.

Your task

Write a query that shows the name and price of every product.

query.sql
-- Show every product's name and price.

SQLite runs right here in your browser. The first run downloads about 0.7 MB; after that it is instant.

Discussion

Stuck? Ask here. Be kind, and share hints rather than full answers.

Loading the discussion…