Learn SQL for Data Analysis

How do you learn SQL for data analysis?

Learn SQL for data analysis in this order: SELECT, WHERE and ORDER BY, then GROUP BY aggregation, joins, subqueries, CTEs and window functions. Write each concept as a query against a real table the same day you read it. Topfolio SQL Basics and SQL Advanced courses cover that exact sequence across seven weeks.

The five-step SQL learning path

Each step assumes the one before it. Skipping ahead to window functions before GROUP BY is comfortable is the single most common reason people stall.

  1. 1

    Query one table

    SELECT, FROM, WHERE, ORDER BY, LIMIT and DISTINCT. Everything else in SQL is built on being able to describe the rows you want.

    SQL Basics course (3 weeks, beginner)
  2. 2

    Turn rows into metrics

    GROUP BY with SUM, COUNT, AVG, MIN and MAX, then HAVING to filter the groups. This is where querying becomes analysis.

    SQL aggregation and GROUP BY practice questions
  3. 3

    Join tables together

    INNER and LEFT JOIN, anti-joins, self-joins and three-table chains. Real schemas never keep the answer in one table.

    SQL join practice questions
  4. 4

    Add subqueries, CTEs and window functions

    The advanced layer that interviews actually test: staged CTEs, correlated subqueries, and rankings and running totals over a window.

    SQL Advanced (Analytics) course (4 weeks, intermediate)
  5. 5

    Rehearse under interview conditions

    Timed question sets and case-style prompts, so the syntax holds up when someone is watching you type.

    SQL Interview and Case Lab course

SQL topic map: what to learn and where to practise it

Every topic below has its own question bank that runs in the browser against a real seeded database — you write the query, execute it, and compare your result set to the expected one. All of it is free.

SQL Aggregation and GROUP BY practice questions

76 questions

Collapse rows into metrics with GROUP BY, SUM, COUNT and AVG, and filter the groups themselves with HAVING. The single largest topic in the bank, because almost every analyst question is an aggregation with the right grouping key.

SQL Joins practice questions

48 questions

Combine tables with INNER and LEFT JOIN, find missing records with anti-joins, compare a row to another row with a self-join, and spot the row multiplication a non-unique key causes.

SQL Window Functions practice questions

32 questions

Rank, running totals and month-over-month deltas without collapsing rows: ROW_NUMBER, RANK, DENSE_RANK, LAG, LEAD and NTILE over a PARTITION BY window.

SQL Subqueries practice questions

16 questions

Scalar, correlated and derived-table subqueries, EXISTS versus IN, the NOT IN NULL trap, and the judgement call about when a join or CTE reads better.

SQL Common Table Expressions practice questions

28 questions

Rewrite deeply nested queries as a readable WITH chain, stage an aggregation for a window function to sit on top of, and walk a hierarchy with a recursive CTE.

SQL Date and Time Functions practice questions

17 questions

Bucket timestamps by month or week, pull parts out with EXTRACT, build rolling 7- and 30-day windows with intervals, and measure the gap between two events.

SQL String Functions practice questions

17 questions

Slice and rebuild text columns with SUBSTR, POSITION and concatenation, match with LIKE and ILIKE, and reach for regular expressions when a wildcard cannot describe the pattern.

SQL Data Cleaning practice questions

17 questions

Handle NULLs with IS NULL and COALESCE, deduplicate by ranking rows with ROW_NUMBER, and normalise messy text with TRIM and LOWER before you group on it.

Once SQL is solid, the same question format continues into Python: pandas DataFrame practice questions cover groupby, merge and vectorised column work — the pandas equivalents of the SQL topics above.

Where to actually write the queries

Reading SQL does not teach SQL. These are the surfaces on Topfolio where you type a query and something runs it.

Want SQL inside a full data analyst curriculum?

SQL Basics and SQL Advanced (Analytics) are the first two milestones of the 12-week Data Analyst Career Track, which continues into Excel, Python, Tableau, portfolio projects and 1:1 mentorship with the founder.

Written guides to read alongside the practice

SQL learning FAQ

How long does it take to learn SQL for data analysis?

At 8-10 hours a week most people can write useful analytical queries in four to six weeks. Topfolio scopes SQL Basics at 3 weeks and SQL Advanced (Analytics) at 4 weeks, so the full beginner-to-interview sequence is about seven weeks of structured study plus ongoing practice.

In what order should I learn SQL topics?

SELECT, WHERE and ORDER BY first, then GROUP BY with the aggregate functions, then joins across multiple tables. Only after those are automatic should you move on to subqueries, common table expressions and window functions. Date, string and data-cleaning functions can be picked up alongside the rest as real datasets demand them.

Do I need to install a database to start practising SQL?

No. Every practice question on Topfolio executes in the browser against a real seeded database, so you write the query and see the result set immediately. There is nothing to install and no local PostgreSQL or MySQL setup to maintain.

Which SQL dialect should I learn as a data analyst?

Learn standard analytical SQL rather than a vendor dialect. Joins, GROUP BY, HAVING, CTEs and window functions behave the same across PostgreSQL, MySQL, SQL Server, Snowflake and BigQuery; only date formatting and string helpers differ meaningfully. Topfolio questions run against real PostgreSQL and SQLite databases for exactly that reason.

Is SQL practice on Topfolio free?

Yes. All SQL and Python practice questions are free, as are two interview practice tests, the career roadmaps, and the first module of every course. Full courses, the remaining interview tests and the Data Analyst Career Track are one-time purchases with lifetime access.

Which SQL topics actually come up in data analyst interviews?

Joins and knowing which type to use, GROUP BY with HAVING, window functions such as ROW_NUMBER, RANK, LAG and LEAD, the choice between a subquery and a CTE, and NULL handling and deduplication. Date bucketing for month-over-month reporting shows up in almost every take-home task.

Should I learn SQL or Python first?

SQL first. It appears in nearly every data analyst job description and is tested in nearly every interview, and the skill transfers unchanged between databases. Add Python and pandas once you can write a multi-table join and a window function without looking anything up.

What is the difference between SQL Basics and SQL Advanced (Analytics)?

SQL Basics is a 3-week beginner course covering SELECT, filtering, sorting, aggregation and joins. SQL Advanced (Analytics) is a 4-week intermediate course covering subqueries, CTEs, window functions and date handling. Take them in that order unless you can already write a multi-table join unaided.