Three small but indispensable verbs: ORDER BY (sort), LIMIT (cap rows), DISTINCT (remove duplicates). You'll use them in nearly every interactive query.
ORDER BY
SELECT first_name, last_name, signed_up_atFROM customersORDER BY signed_up_at DESC;
DESC = descending (newest first). ASC = ascending (default). You can sort by multiple columns:
SELECT *FROM ordersORDER BY country ASC, total_amount DESC;
First sort by country (A-Z), then within each country sort by total_amount (high-to-low).
LIMIT
SELECT * FROM ordersORDER BY total_amount DESCLIMIT 10;
Top 10 orders by amount. LIMIT is essential for exploration — never run a SELECT * on a million-row table without one.
Pagination
Use LIMIT 20 OFFSET 40 to skip 40 rows and return the next 20 — page 3 of a 20-per-page paginated view. (Postgres also accepts FETCH FIRST 20 ROWS, but LIMIT is portable.)
DISTINCT
SELECT DISTINCT country FROM customers ORDER BY country;
Returns the unique list of countries. DISTINCT applies to the entire row in the SELECT — DISTINCT a, b returns unique (a, b) pairs, not unique a OR unique b.
Exercise
Find the 5 most recent customers from Kenya, ordered newest first.