Module 1 · Selecting data

Select data with SELECT and FROM

By the end you will be able to choose which columns to read and from which table.

About 10 min

0 of 52 lessons

Before you start, you need

How to read a SQL query

Choose columns and their table

To build a catalogue you need each product's name and price. The table also stores stock and categories, but there is no need to show everything. Choose the columns that answer the question.

SELECT goes before the names of those columns. FROM goes before the table. So SELECT name, price FROM products means “read the name and price of every product”.

Separate columns with commas and use their names exactly as they appear in the table. Without the comma, SELECT name price can be read as a single column with a different name. In the exercises you can open “View tables and data” to check the column headings.

Choosing fewer columns does not delete rows: we still see every product. SELECT * shows every column and is useful for exploring; once you know what you need, write the column names.

Minimal syntax
SELECT column_1, column_2
FROM table_name;

See it in action

We want a simple catalogue with the name and price of each product.

SQL
SELECT name, price
FROM products;
Example result: 8 of 9 rows
nameprice
Mouse24.9
Keyboard49.5
Monitor 24179
Pro Laptop999
Headphones69.9
Monitor 27249
SSD Drive89
Cable USB-C12
  1. FROM products reads the nine rows of the catalogue. SELECT picks two properties of each product.
  2. The result has nine rows and two columns. It does not include stock because we did not ask for it.
  3. Separate name and price with a comma. Without it, name price could be interpreted as a renamed column rather than two columns.
  4. To explore every property you can use SELECT *. Then go back to a specific selection that answers the question.

Practice with help

Getting things wrong is part of learning: you can run your query as many times as you like and nothing is lost. If you get stuck, open a hint (each one reveals a bit more) and save the solution for last.

Guided practice

Prepare a product list

Not started

Write a query that returns the name, category and stock of every product.

Expected result: 9 rows with the columns name, category, stock, in that order. Row order does not matter.

View tables and data

Open this panel to see the full data.

Your turn

Solve this variation. Spot the part that has changed before you look for help.

Practice

Build a catalogue

Not started

Show the id and name of every category. Keep that column order; any row order is fine.

Expected result: 5 rows with the columns id, name, in that order. Row order does not matter.

View tables and data

Open this panel to see the full data.

Key takeaways

  • SELECT picks the columns.
  • FROM names the table.
  • Separate columns with commas.

Next: Choose the order of the columns