SQL Essentials: Think in Tables
SQL is not merely another programming syntax. Its superpower is that you describe the result you want from relational data.
table row column primary key foreign key SELECT WHERE GROUP BY HAVING ORDER BY JOIN NULL aggregate
The mental model
FROM / JOIN → Which data?
WHERE → Which rows?
GROUP BY → Which groups?
HAVING → Which groups survive?
SELECT → What output?
ORDER BY → In what order?
Example:
SELECT department,
AVG(salary) AS avg_salary
FROM employees
WHERE active = TRUE
GROUP BY department
HAVING COUNT(*) >= 5
ORDER BY avg_salary DESC;Start here
★ SQLBolt
Excellent first resource because lessons and exercises run interactively in the browser.
https://sqlbolt.com/
★ PostgreSQL Tutorial
A more formal path through relational concepts, queries, joins, aggregates and advanced features.
https://www.postgresql.org/docs/current/tutorial.html
★ SQLite Tutorial / Docs
Useful when you want a lightweight local database requiring little setup.
https://www.sqlite.org/docs.html
Practice order
SELECT
↓
WHERE + ORDER BY
↓
GROUP BY + aggregates
↓
INNER / LEFT JOIN
↓
CASE
↓
subqueries / CTEs
↓
window functions
If you can confidently combine JOIN + GROUP BY + CASE + window functions, you can solve a large fraction of everyday analytical SQL tasks.
Practice
- SQLBolt: https://sqlbolt.com/
- HackerRank SQL: https://www.hackerrank.com/domains/sql
- LeetCode Database problems: https://leetcode.com/problemset/database/
Next: Analytical SQL & Interview Patterns