Skip to content
Module 02 of 1240 min readBeginner

SELECT, FROM, WHERE

Pull rows out of a table with filters that match your question, not the other way around.

17%

Listen along

Read “SELECT, FROM, WHERE” aloud

Plays in your browser using on-device text-to-speech — nothing leaves the page.

Every query starts with SELECT. It's the verb that says 'give me back this data'. The simplest possible query:

sql
SELECT * FROM customers;

Translation: give me every column (* means all columns) from the customers table. The output is the full table, every row.

Picking specific columns

sql
SELECT first_name, last_name, country FROM customers;

Now we get only three columns. Always prefer naming columns over SELECT *. It's faster, more explicit, and survives schema changes.

WHERE: filtering rows

WHERE adds a condition. Only rows where the condition is true come back.

sql
SELECT first_name, last_name
FROM customers
WHERE country = 'Kenya';

Conditions can be combined with AND, OR, and NOT. Use parentheses when in doubt — operator precedence is real but not worth memorizing.

sql
SELECT *
FROM customers
WHERE country = 'Kenya'
AND signed_up_at > '2024-01-01'
AND (plan = 'pro' OR plan = 'enterprise');

Common operators in WHERE

  • = and != (or <>) for equality / inequality
  • <, <=, >, >= for comparisons
  • IN ('a', 'b', 'c') — membership in a list
  • BETWEEN x AND y — inclusive range
  • LIKE '%pattern%' — pattern matching with % (any chars) and _ (one char)
  • IS NULL / IS NOT NULL — never use = NULL; NULL is the absence of a value, not a value itself

NULL is special

NULL = NULL is not true; it is unknown. Always use IS NULL / IS NOT NULL. This trips up beginners constantly. We'll cover NULL handling deeply in module 8.

Exercise

Write a query that returns customer email and country for customers in Kenya, Nigeria, or South Africa who signed up in 2024.

Loading progress…
LeadAfrikPublic Economics Hub