RadarTrek

Quick Reference

SQL for Builders — Cheat Sheet

Every query pattern from the course, organised by category. Print it, save it, reference it.

Read Data (SELECT)

SELECT * FROM users;Get all columns from the users table
SELECT name, email FROM users;Get specific columns only
SELECT name AS customer FROM users;Rename a column in the result (alias)
SELECT COUNT(*) FROM users;Count all rows
SELECT DISTINCT plan FROM users;Get unique values only

Filter Rows (WHERE)

WHERE plan = 'pro'Exact match — use single quotes for text
WHERE amount > 50Greater than — also < >= <=
WHERE plan != 'free'Not equal (<> also works)
WHERE email LIKE '%@gmail.com'Pattern match — % is wildcard
WHERE plan IN ('pro', 'enterprise')Match any value in list
WHERE cancelled_at IS NULLColumn has no value
WHERE amount BETWEEN 10 AND 50Inclusive range
WHERE plan = 'pro' AND amount > 100Both conditions must be true
WHERE plan = 'free' OR plan = 'trial'Either condition true

Sort & Limit

ORDER BY created_at DESCNewest first (descending)
ORDER BY name ASCA-Z (ascending — default)
ORDER BY plan, created_at DESCSort by multiple columns
LIMIT 10Return only 10 rows
LIMIT 10 OFFSET 20Skip 20, then take 10 (page 3)

Aggregate Functions

COUNT(*)Count all rows including nulls
COUNT(email)Count non-null values in a column
SUM(amount)Total of a numeric column
AVG(amount)Average value
MAX(amount)Largest value
MIN(amount)Smallest value

Group Data (GROUP BY)

GROUP BY planGroup rows that share the same plan value
GROUP BY u.id, u.nameGroup by multiple columns
HAVING COUNT(*) > 3Filter groups after aggregation
HAVING SUM(amount) > 1000Only groups with total over 1000

Join Tables

JOIN users u ON o.user_id = u.idInner join — only matching rows
LEFT JOIN orders o ON o.user_id = u.idAll users, even with no orders
WHERE o.id IS NULLUsed after LEFT JOIN to find unmatched rows

Write Data (INSERT / UPDATE / DELETE)

INSERT INTO users (name, email) VALUES ('Ama', 'ama@co.com');Add a new row
UPDATE users SET plan = 'pro' WHERE id = 42;Change a specific row
DELETE FROM orders WHERE id = 99;Remove a specific row

Query anatomy — full example

SELECT u.name, SUM(o.amount) AS total_spend   -- 1. What to return
FROM users u                                    -- 2. Main table (alias u)
JOIN orders o ON o.user_id = u.id              -- 3. Join another table
WHERE u.plan = 'pro'                           -- 4. Filter rows
  AND o.status = 'paid'
GROUP BY u.id, u.name                          -- 5. Group rows
HAVING SUM(o.amount) > 100                     -- 6. Filter groups
ORDER BY total_spend DESC                      -- 7. Sort
LIMIT 10;                                      -- 8. Cap rows returned

SQL processes in this order: FROM → JOIN → WHERE → GROUP BY → HAVING → SELECT → ORDER BY → LIMIT

Real-world queries every builder needs

Monthly revenue

SELECT SUM(amount) AS mrr
FROM orders
WHERE status = 'paid'
  AND created_at >= DATE_TRUNC('month', NOW());

New users this week

SELECT COUNT(*) AS new_users
FROM users
WHERE created_at >= NOW() - INTERVAL '7 days';

Top 10 by spend

SELECT u.name, SUM(o.amount) AS spend
FROM users u
JOIN orders o ON o.user_id = u.id
WHERE o.status = 'paid'
GROUP BY u.id, u.name
ORDER BY spend DESC
LIMIT 10;

Users with 0 orders

SELECT u.name, u.email
FROM users u
LEFT JOIN orders o ON o.user_id = u.id
WHERE o.id IS NULL;

Safe write workflow

1.SELECT first — check what you're about to change
2.Add WHERE before UPDATE or DELETE — never skip it
3.LIMIT 10 on big tables before removing LIMIT
4.Test in staging before running on production

RadarTrek Intel — monthly score updates

We track 40+ tools so you don't have to. Score changes, new tools, and new guides — once a month, no spam.