Skip to content
Getting Digital

Data, Analytics and AI

SQL for analysis

SQL is the point where an analyst stops waiting for somebody else's export. This page treats the language as analysts use it: selecting, joining, grouping and windowing inside a warehouse, reading tables other people designed, and writing queries a colleague can check line by line. Designing those tables for an application is developer work and lives under programming; here the concern is getting an answer out of them that holds up.

Why this topic exists: Querying, joining, aggregating and windowing data is the analyst's first real tool and the language of every warehouse (DP-900 relational concepts; DMBOK Data Storage and Operations; the programming field owns database design).

SQL for analysis is a narrower set of habits than SQL for building applications. The analyst reads far more than writes, works in tables somebody else designed and is judged on whether a number is right, not on whether a transaction commits quickly. Microsoft's DP-900 places the language inside its relational concepts area, beside normalisation and common database objects, and DMBOK files the stores themselves under Data Storage and Operations. Neither framework is about analysis as such, which is why the analyst's craft is learned mostly in practice. The questions arrive from colleagues in plain language, and translating them into the right tables is half the work.

Five moves that cover most questions

  • Filter and select. Choosing columns and rows, with care over how NULL behaves in comparisons.
  • Join. Combining tables on keys, and knowing before running the query how many rows each side should contribute.
  • Aggregate. GROUP BY with counts, sums and averages, and HAVING to filter the groups themselves.
  • Window. Rankings, running totals and comparisons with the previous row, computed without collapsing rows the way grouping does.
  • Structure. Common table expressions that break a long query into named steps a colleague can read from top to bottom.

Behind the moves sits the idea that decides most errors: grain. Every table has one, a row per order, per order line or per customer per day. Join an orders table to its lines and then sum the order totals, and each order is counted once for every line it contains. The query runs, the figure looks plausible and it is wrong. Distinct counts carry the same trap in reverse: counting customers after joining them to their orders works only with a distinct count of the key, and an average of averages misleads whenever the groups differ in size. Comparing row counts before and after each join is the cheapest habit in analytics.

The beginner's mistake

Learning syntax on a tutorial database of five tidy tables and then freezing in front of a warehouse with eight hundred. The real skill is reading a schema: finding the documentation and the keys, noticing which tables are views over others, and asking the owner what a column actually holds before trusting it.

Where the queries run

Analytical SQL now mostly runs in cloud warehouses such as Snowflake, which charge for compute, so a careless scan of a large table costs money as well as time. Pipelines built through data engineering fill those warehouses, and dbt lets analysts turn their queries into versioned, tested models inside the same pipeline. For practice away from work, freeCodeCamp's Relational Databases certification has learners build and query real databases at no cost, and the SQL tool page covers dialects and engines. Designing the tables belongs to databases and SQL under programming. Turning results into charts continues in data visualisation and BI, and the framing of a question before any query is written sits under data analysis fundamentals.

Next to this topic

Concepts to know

Glossary entries with the reason each one matters here.

Certifications that test it

Vendor exams and free certificates; facts, cost and the preparation path are on each page, and the certifications hub has them all.

Tools of the trade

  • SQL

    The analyst's first real tool.

  • Snowflake

    Where analytical SQL runs.

  • dbt

    Turns analysts' SQL into versioned, tested models.

Frequently asked

How much SQL does a data analyst need?
Enough to answer a new question against an unfamiliar schema without help: joins across several tables, grouping, window functions and common table expressions. Interview tasks usually test exactly those, often with a trap involving NULLs or duplicated rows.
Which SQL dialect should I learn first?
Any major one. PostgreSQL, SQL Server, BigQuery and Snowflake differ in date functions and a handful of keywords, not in the core. Learn one well, keep notes on the differences you meet, and expect a short period of adjustment after switching.
Should an analyst learn SQL or Python first?
SQL, in most jobs, because the data lives in a database and the first task is getting it out correctly. Python for data earns its place once the work outgrows what a single query can do.

Courses in the directory

71 courses are filed here; the top 6 by our ranking, details and the provider link on each course page.

Browse the directory shelf

Last reviewed 26 September 2026 · Getting Digital