SQL
4 min read
BEGINNER
SELECT and FROM
Quick AnswerSELECT specifies what to return; FROM identifies the source relation. A query produces a result table without necessarily changing stored data. Here we use the read-only shop queries.
Core idea
SELECT specifies what to return; FROM identifies the source relation. A query produces a result table without necessarily changing stored data. Here we use the read-only shop queries.
Minimal example
sql
SELECT name FROM products ORDER BY id;Expected rows (in order):
text
NotebookPenBagPencilHow it works
A SELECT list may contain a single column or several columns. FROM products makes the product columns available. ORDER BY id is included for repeatable output; without ordering, row order is not guaranteed. SELECT without FROM can compute a constant in PostgreSQL and SQLite.
Practical example
sql
SELECT id, customer_id FROM orders ORDER BY id;Expected rows (in order):
text
101 | 1102 | 1103 | 2Common mistake and practice
Do not write FROM name: name is a column, not the table. Ask for the customer names from customers, ordered by id. Predict three rows.