To learn SQL for data analysis, study the core commands in this order: SELECT and WHERE, ORDER BY and LIMIT, aggregate functions with GROUP BY and HAVING, JOINs, subqueries and CTEs, then window functions. Write queries every day against a real dataset. Most beginners can handle everyday analyst queries in four to six weeks of regular practice, but reading about SQL is not enough: you learn it by writing and debugging queries.
What analysts actually use SQL for
Analysts use SQL to pull data out of databases, filter it, combine tables, summarise it and prepare it for a dashboard or a model. You are mostly reading data, not designing databases, so focus on SELECT queries first.
A six-week plan
| Week | Topics | Practice |
|---|---|---|
| 1 | SELECT, FROM, WHERE, AND/OR/NOT, IN, LIKE, BETWEEN, ORDER BY, LIMIT, NULL | Answer 20 questions on one table |
| 2 | COUNT, SUM, AVG, MIN, MAX; GROUP BY; HAVING; DISTINCT; CASE WHEN | Summarise sales by month, by region |
| 3 | INNER JOIN, LEFT JOIN, joining 3+ tables, keys, one-to-many | Join customers, orders and products |
| 4 | Subqueries, CTEs (WITH), UNION, handling duplicates | Rewrite a nested query as CTEs |
| 5 | Window functions: ROW_NUMBER, RANK, SUM() OVER, LAG/LEAD, PARTITION BY | Running totals, top N per group, month-on-month change |
| 6 | Dates and strings, performance basics, a mini project | Answer 10 business questions end to end |
The concepts that trip people up
Order of execution
SQL runs in a different order than you write it: FROM and JOIN, then WHERE, GROUP BY, HAVING, SELECT, ORDER BY, LIMIT. That is why you cannot use a column alias from SELECT in WHERE, and why WHERE filters rows before grouping while HAVING filters groups after.
Joins
Draw two small tables and walk through what INNER JOIN and LEFT JOIN return. Check row counts before and after a join: if they jump unexpectedly, you have a one-to-many relationship duplicating rows.
NULL
NULL means unknown, so NULL = NULL is not true. Use IS NULL. Aggregates such as AVG ignore NULLs, which changes your results.
Window functions
A window function calculates across related rows without collapsing them as GROUP BY does. SUM(amount) OVER (PARTITION BY customer ORDER BY date) gives a running total per customer. They are the feature that most separates beginners from confident analysts and are common in interviews.
Practise on real data
- Install a free database such as SQLite, PostgreSQL or DuckDB so you can run queries locally.
- Load a public dataset: airline flights, NYC taxi trips, Stack Overflow data, your country's open government data, or a Kaggle CSV you find interesting.
- Write questions first, then queries: "Which month had the most refunds? Which customers ordered more than three times?"
- Use practice sites with checked answers such as SQLZoo, Mode's SQL tutorial, LeetCode or HackerRank database problems, and StrataScratch.
- Re-solve problems a week later without looking at your answer.
Use recall to make syntax stick
SQL has a small vocabulary, and typing it repeatedly is the best way to own it. Flashcards help for the things you forget: the order of clauses, the difference between WHERE and HAVING, window frame syntax. Type to Study can build a course on SQL from a topic, or from a textbook or course notes you upload, with flashcards and typed answers for the key points. See its SQL subject page. It does not run queries against a database, so you still need a real SQL environment for practice.
A mini project to finish
Pick a dataset with at least three related tables. Write ten business questions, answer them in SQL, and put the queries and your findings in a GitHub repository with a short README. That is a portfolio piece and an interview talking point.
Mistakes to avoid
- Only watching tutorials. Always write queries.
- Using SELECT * everywhere. Name your columns.
- Not checking results. Compare to a count you know is right.
- Learning one dialect only. The core is the same across them, with small differences in dates and strings.
- Skipping window functions.
Stick to a short daily session. Thirty to sixty minutes of writing queries beats a weekend binge, because the commands return to memory just as you start to forget them.