appzasGamesToolsDevLearnCheat sheetsQuick calcsConvertersReferenceNetworkTimeCalculatorsCompareLLM prices

SELECT, WHERE and ORDER BY

Lesson 1 of 49 minBeginner

Tables, rows and columns, and how to pick and filter them.

A relational database stores data in tables: each row is a record, each column is a field. SQL (Structured Query Language) is how you ask questions. Examples use this table, users:

idnamecountryage
1AnaES31
2BobUS45
3ChenUS28
4DaraIE39

Read data

SELECT name, age FROM users;                       -- chosen columns
SELECT * FROM users;                               -- every column
SELECT * FROM users WHERE country = 'US';          -- filter rows
SELECT * FROM users WHERE age >= 30 AND country <> 'ES';
SELECT * FROM users ORDER BY age DESC;             -- sort, highest first
SELECT * FROM users ORDER BY age DESC LIMIT 2;     -- only the first 2

Useful filters

  • IN ('US','IE') matches any value in a list.
  • BETWEEN 30 AND 40 matches an inclusive range.
  • LIKE 'A%' matches text starting with A (% is any characters).
  • IS NULL finds missing values: = NULL never matches.

NoteText values use single quotes. Double quotes are for identifiers in standard SQL.

Test yourself

Answer all the questions, then check them. Finish with every answer right to mark the lesson as done.

HintSELECT, a star, FROM.
HintUse WHERE with single quotes around the text.
HintORDER BY ... DESC.
4. How do you find rows where email is missing?

Key terms