The workhorse of SQL is the SELECT statement. Every analytics
question starts here.
The shape of a query
SQL
SELECT order_id, customer_id, amount
FROM orders
WHERE amount > 100
ORDER BY amount DESC
LIMIT 5;
The workhorse of SQL is the SELECT statement. Every analytics
question starts here.
SELECT order_id, customer_id, amount
FROM orders
WHERE amount > 100
ORDER BY amount DESC
LIMIT 5;
Reading order matters: FROM picks the table, WHERE filters rows,
SELECT picks columns, ORDER BY sorts, LIMIT truncates.
-- multiple conditions
WHERE status = 'shipped' AND amount > 100
-- membership
WHERE country IN ('FR', 'DE', 'NL')
-- pattern matching
WHERE email LIKE '%@example.com'
-- null checks (never use = NULL)
WHERE shipped_at IS NOT NULL
Exercise: from an orders table, find the 10 most recent orders over
€50 that have actually shipped.
Sign in to track your progress.
0 of 3 done
Question 1
Which filter keeps only the orders that have shipped?
Question 2
Fill the blank to keep orders from France, Germany or the Netherlands: WHERE country ___ ('FR', 'DE', 'NL')
Question 3
Put the clauses in the order the database runs them.
Your order
Pick lines from the list in the order they run.
Lines
Your answers aren't saved. Sign in to keep your progress.