Skip to the content.

How to Master SQL: The Complete 2027 Roadmap for SQL and Databases

A free, staged path from your first SELECT to designing schemas, tuning queries and running PostgreSQL in production, with time estimates, the best free practice sites, projects and interview prep.

Last reviewed: December 2026 (PostgreSQL 19, MySQL 9.7 LTS, SQLite 3.x, DuckDB 1.x)

If you want to learn SQL in 2027, whether for data analysis, backend development or data engineering, this roadmap tells you what to study, in what order, how long it takes and which free resources are worth your time. SQL is over 50 years old and still the most widely used language for working with data: nearly every application, analytics tool and data warehouse speaks it. Learning to write queries takes weeks; mastering databases (modeling, indexing, transactions, performance) is what makes you valuable.


Table of contents


Who this roadmap is for

Goal Focus on Time to competence
Data / business analyst Stages 1-3, analyst track 6-10 weeks
Backend developer Stages 1-6 3-5 months
Data engineer Stages 1-5, 7, data engineer track 4-6 months
DBA / database reliability Everything, especially 5-8 6-12 months+

Estimates assume 8-12 hours a week of active practice, which means writing queries, not just reading.


Which database should you learn?

SQL is a standard, but every database has a dialect. Learn one well; switching later takes days, not months.

Database Type Best for Learning pick?
PostgreSQL Open-source relational server General backend, analytics, extensions (PostGIS, pgvector) Best overall pick: standards-friendly, powerful, widely used
MySQL / MariaDB Open-source relational server Web apps, WordPress/PHP stacks, many legacy systems Good if your job uses it
SQLite Embedded, single-file Mobile, desktop, small sites, testing, learning Great for first steps (zero setup)
DuckDB Embedded analytical (columnar) Local analytics on CSV/Parquet files Great for analysts and data engineers
SQL Server Commercial (free Developer edition) Enterprise, .NET shops Learn if your employer uses it
Oracle Commercial Large enterprises Learn on the job
Snowflake / BigQuery Cloud data warehouses Analytics at scale Learn after the basics

Best pick: start with PostgreSQL (or SQLite for the first week), then pick up DuckDB if you do analytics.

Current versions: PostgreSQL 19 was released on 19 November 2026 (announcement); see the versioning policy for support windows. MySQL 9.7 became the new LTS line in April 2026, and MySQL has since switched to calendar-based version numbers for later releases.


The roadmap at a glance

Stage 0  Setup                    1 day       Postgres or SQLite + a client
Stage 1  Querying basics          2-3 weeks   SELECT, WHERE, ORDER BY, NULL, functions
Stage 2  Joins + aggregation      2-4 weeks   JOINs, GROUP BY, HAVING, subqueries
Stage 3  Advanced SQL             3-4 weeks   CTEs, window functions, recursion, JSON
Stage 4  Data modeling            2-4 weeks   keys, normalization, constraints, migrations
Stage 5  Performance              3-5 weeks   indexes, EXPLAIN, query plans
Stage 6  Transactions             2-3 weeks   ACID, isolation, locking, MVCC
Stage 7  Production               ongoing     backups, replication, security, monitoring
Stage 8  Internals                ongoing     storage, B-trees, query optimizers

Stage 0: Setup (1 day)

Option How Notes
Browser only DB Fiddle or SQL Fiddle No install; good for quick experiments and sharing
SQLite Usually preinstalled on macOS/Linux; CLI docs One file, zero config
PostgreSQL Native installer, Homebrew, your Linux package manager, or Docker (docker run -e POSTGRES_PASSWORD=dev -p 5432:5432 postgres) Use psql plus a GUI
DuckDB Single binary; docs Query CSV/Parquet directly

GUI clients (free): DBeaver (community edition), pgAdmin, Beekeeper Studio (community edition), DB Browser for SQLite. Better terminal: pgcli (autocomplete for psql).


Stage 1: Querying basics (2-3 weeks)

Learn

The logical order of a query

SQL is written in one order and evaluated in another. Knowing this explains most beginner errors (for example why you can’t use a SELECT alias in WHERE):

FROM / JOIN  ->  WHERE  ->  GROUP BY  ->  HAVING  ->  SELECT  ->  DISTINCT  ->  ORDER BY  ->  LIMIT

Julia Evans’ short illustrated post SQL queries don’t start with SELECT explains this well.

Free resources

Resource Format Why
SQLBolt Interactive lessons Best first stop: short lessons with exercises in the browser
SQLZoo Interactive tutorials Lots of graded practice on real-ish datasets
Khan Academy: Intro to SQL Video + exercises Very gentle for complete beginners
Kaggle Learn: Intro to SQL Notebooks (BigQuery) Good for aspiring analysts
PostgreSQL tutorial (official) Docs Short, authoritative
freeCodeCamp: SQL full course Video (~4 h) Covers basics through joins in one sitting

Exercises

  1. Finish all SQLBolt lessons.
  2. On a sample database (see below), answer: the 10 most expensive products; customers with no phone number; orders placed in the last 30 days of the data.
  3. Write a CASE expression that buckets orders into small/medium/large.

Stage 2: Joins, aggregation and subqueries (2-4 weeks)

Learn

-- Customers who have never placed an order
SELECT c.customer_id, c.name
FROM customers AS c
WHERE NOT EXISTS (
    SELECT 1 FROM orders AS o WHERE o.customer_id = c.customer_id
);

Free resources

Resource Why
Select Star SQL Free interactive book built around one real dataset; excellent on aggregation
PostgreSQL Exercises Graded exercises on one schema, from simple to window functions
SQL Murder Mystery Solve a crime with joins; surprisingly good practice
ThoughtSpot (formerly Mode) SQL tutorial Analyst-focused, basic to advanced
Neon PostgreSQL tutorial Large, example-driven Postgres reference (formerly postgresqltutorial.com)

Exercises

  1. Complete the “Joins” and “Aggregation” sections of PostgreSQL Exercises.
  2. Solve SQL Murder Mystery without hints.
  3. Revenue per product category per month; categories whose revenue fell month over month (you’ll redo this more elegantly with window functions in Stage 3).

Stage 3: Advanced SQL (3-4 weeks)

This is where people go from “knows SQL” to “good at SQL”.

Learn

-- Top 3 products by revenue in each category
WITH product_revenue AS (
    SELECT p.category, p.name, SUM(oi.quantity * oi.unit_price) AS revenue
    FROM order_items AS oi
    JOIN products AS p USING (product_id)
    GROUP BY p.category, p.name
)
SELECT category, name, revenue
FROM (
    SELECT *, ROW_NUMBER() OVER (PARTITION BY category ORDER BY revenue DESC) AS rn
    FROM product_revenue
) ranked
WHERE rn <= 3
ORDER BY category, revenue DESC;
-- Month-over-month change with LAG
SELECT month,
       revenue,
       revenue - LAG(revenue) OVER (ORDER BY month) AS change
FROM monthly_revenue;

Free resources

Resource Why
Modern SQL Explains newer standard SQL features and which databases support them
Kaggle Learn: Advanced SQL Window functions and nested data, hands-on
Window Functions practice Focused drills
PostgreSQL docs The reference you’ll use forever

Exercises

  1. Running 7-day average of daily signups.
  2. Sessionize click events: a new session starts after 30 minutes of inactivity (classic LAG + running SUM trick).
  3. Walk an employee/manager tree with a recursive CTE and output each person’s depth and full reporting chain.
  4. Retention cohort table: for each signup month, the % of users active 1, 2, 3 months later.

Stage 4: Data modeling and schema design (2-4 weeks)

Learn

Read the PostgreSQL wiki page Don’t Do This; it’s a short list of common modeling mistakes with reasons.

Exercises

  1. Design a schema for a library (books, copies, members, loans, holds). Enforce “a copy can’t be loaned twice at once” in the database, not only in app code.
  2. Design an e-commerce schema with orders, line items, price history and discounts. Draw it in dbdiagram.io (free tier).
  3. Take a messy single-table spreadsheet export and normalize it into 3NF with migrations.

Stage 5: Indexes and query performance (3-5 weeks)

The single most valuable skill for backend developers working with databases.

Learn

EXPLAIN (ANALYZE, BUFFERS)
SELECT * FROM orders
WHERE customer_id = 42 AND created_at >= now() - interval '30 days'
ORDER BY created_at DESC
LIMIT 20;

-- An index that serves both the filter and the sort:
CREATE INDEX CONCURRENTLY orders_customer_created_idx
    ON orders (customer_id, created_at DESC);

Resources

Resource Cost Why
Use The Index, Luke Free online Best pick: the clearest explanation of SQL indexing for developers, covering several databases
SQL Performance Explained Paid (book version of the above) Same author; support the free site
explain.dalibo.com and explain.depesz.com Free Paste a Postgres plan, get it visualized/annotated
Hussein Nasser (YouTube) Free Long-form explanations of database and backend internals

Exercises

  1. Generate 10 million rows with generate_series. Time a query, add an index, compare EXPLAIN ANALYZE before and after.
  2. Find a query where a composite index in the wrong column order isn’t used; fix it.
  3. Replace OFFSET pagination with keyset pagination and measure page 10,000.

Stage 6: Transactions and concurrency (2-3 weeks)

Learn

-- A simple, safe job queue worker in Postgres
BEGIN;
SELECT id, payload FROM jobs
WHERE status = 'pending'
ORDER BY id
FOR UPDATE SKIP LOCKED
LIMIT 1;
-- ...process...
UPDATE jobs SET status = 'done' WHERE id = $1;
COMMIT;

Exercise

Simulate two bank transfers that run concurrently in two psql sessions. Reproduce a lost update under Read Committed, then prevent it with FOR UPDATE, a CHECK constraint, and Serializable isolation with retries. Write down what each approach costs.


Stage 7: Operating databases in production (ongoing)

Topic What to know Reference
Backups Logical (pg_dump) vs physical; point-in-time recovery; test restores Backup and restore
Replication & HA Streaming replication, read replicas, failover High availability
Security Least-privilege roles, row-level security, TLS, no superuser apps Row security
Maintenance Autovacuum tuning, bloat, reindexing; PG 19 adds REPACK (CONCURRENTLY) Release notes
Monitoring pg_stat_statements, slow-query logs, connection counts, replication lag Postgres docs
Upgrades Major-version upgrades with pg_upgrade or logical replication Postgres docs
Schema changes Zero-downtime migrations: add column nullable, backfill in batches, then constrain Your migration tool’s docs
Managed services RDS, Cloud SQL, Azure, Neon, Supabase, Crunchy Bridge and others (all paid beyond free tiers) Provider docs

Extensions worth knowing: pgvector (vector similarity search for AI apps), PostGIS (geospatial), Citus (distributed Postgres), TimescaleDB from Tiger Data (time series). The awesome-postgres list collects many more.


Stage 8: Database internals and mastery (ongoing)

Understanding how databases work inside makes you dramatically better at using them.

Resource Cost What you get
CMU 15-445/645 Intro to Database Systems Free (lectures on YouTube) Best pick: storage, buffer pools, B+trees, hashing, query execution, optimization, concurrency control, recovery; with programming projects
Berkeley CS 186 Free course materials Another excellent university database course
Stanford Databases (online) Free self-paced Relational algebra, SQL, design theory
Designing Data-Intensive Applications, 2nd edition, by Martin Kleppmann and Chris Riccomini Paid (O’Reilly, book site) The standard book on how data systems work; 2nd edition published 2026 (author’s post)
Database Internals by Alex Petrov Paid (site) Storage engines and distributed systems in depth

Mastery projects:

  1. Build a tiny key-value store with a write-ahead log and crash recovery.
  2. Implement a B+tree with insert, search and range scan.
  3. Write a toy SQL parser and executor for SELECT ... WHERE over CSV files.
  4. Contribute documentation or a small fix to an open-source database or extension.

Tracks: analyst vs backend vs data engineer

Topic Analyst Backend dev Data engineer
Joins/aggregation Essential Essential Essential
Window functions Essential Useful Essential
Schema design Nice to have Essential Essential (warehouse modeling)
Indexes / EXPLAIN Useful Essential Useful (plus partitioning, clustering)
Transactions / locking Rarely Essential Useful
Tools BI tools, spreadsheets, DuckDB, warehouses ORMs, migrations, Postgres/MySQL dbt, orchestration, Spark, warehouses, Parquet
Next skill Statistics, Python/pandas Caching, queues, system design Pipelines, streaming, data quality

Best free resources

Interactive learning

References

Video


Books (free and paid)

Book Cost Level Why read it
Use The Index, Luke Free online Intermediate Indexing for developers
Select Star SQL Free online Beginner Interactive, data-driven
PostgreSQL docs: tutorial + manual Free All Unusually well written
Learning SQL (3rd ed.) by Alan Beaulieu Paid (O’Reilly) Beginner Clear, database-neutral introduction
SQL Antipatterns, Volume 1 by Bill Karwin Paid Intermediate Common design mistakes and fixes
The Art of PostgreSQL by Dimitri Fontaine Paid Intermediate Using Postgres features from application code
Designing Data-Intensive Applications (2nd ed.) Paid Advanced Data systems design
Database Internals Paid Advanced How storage engines work

Tools

Need Tools
GUI client DBeaver, pgAdmin, Beekeeper Studio, DB Browser for SQLite
Terminal psql, pgcli, sqlite3, duckdb
Plan visualizing explain.dalibo.com, explain.depesz.com
Diagramming dbdiagram.io
Linting/formatting SQLFluff, sqlformat.org
Online sandboxes DB Fiddle, SQL Fiddle
Popularity data DB-Engines ranking, Stack Overflow Developer Survey

Sample databases to practice on

Dataset Databases Good for
Chinook Many (SQLite, Postgres, MySQL, SQL Server…) Music store: joins, aggregation
Sakila MySQL (ports exist for others) DVD rental: classic teaching schema
Employees test DB MySQL ~4 million rows: performance practice
Postgres sample databases (Neon) PostgreSQL Several ready-to-load datasets
PostgreSQL Exercises schema PostgreSQL Country club bookings, used on pgexercises.com

Project ideas

Beginner

  1. Personal finance tracker: import your bank CSV into SQLite or DuckDB, categorize transactions with CASE, monthly summaries.
  2. Movie database explorer: load a public dataset, answer 20 questions you write yourself.
  3. Library schema with constraints enforced by the database.

Intermediate

  1. Analytics dashboard backend: retention cohorts, funnels and moving averages in pure SQL, served by a small API.
  2. E-commerce schema with migrations, seed data, and 10 optimized reporting queries with EXPLAIN notes.
  3. Job queue in Postgres using FOR UPDATE SKIP LOCKED, with retries and dead-letter handling.

Advanced

  1. Zero-downtime migration playbook: rename a column on a 50M-row table without downtime; document each step.
  2. Multi-tenant SaaS with row-level security policies and tests proving tenants can’t see each other’s data.
  3. Semantic search with pgvector plus full-text search, combined ranking.
  4. Toy database engine (see Stage 8).

SQL interview preparation

Interviews for analyst, data and backend roles commonly test:

Pattern Example prompt Key technique
Top-N per group Top 3 salaries per department DENSE_RANK() OVER (PARTITION BY ...)
Second highest Second highest salary DENSE_RANK, or OFFSET 1 with DISTINCT
Running totals Cumulative revenue by day SUM() OVER (ORDER BY ...)
Gaps and islands Consecutive login streaks Row number difference trick
Anti-join Customers with no orders NOT EXISTS / LEFT JOIN ... IS NULL
Deduplication Keep latest row per user ROW_NUMBER() then filter = 1
Period-over-period Month-over-month growth LAG()
Retention / cohorts Day-7 retention Self-join or conditional aggregation
Pivot Rows to columns SUM(CASE WHEN ...) or FILTER
Self-join Employees earning more than managers Join table to itself

Practice sites: LeetCode SQL 50 study plan and the LeetCode database problem set (free tier plus paid premium problems), HackerRank SQL (free), DataLemur (free and paid questions), StrataScratch (free and paid).

Interview tips:


Common mistakes

  1. WHERE col = NULL instead of IS NULL.
  2. NOT IN (subquery) when the subquery can return NULL (returns nothing). Use NOT EXISTS.
  3. Filtering a LEFT JOINed table in WHERE instead of the ON clause.
  4. COUNT(col) when you meant COUNT(*) (or vice versa).
  5. Fan-out: joining two one-to-many tables then summing, which double counts.
  6. Floats for money; timestamp without time zone for real-world events.
  7. SELECT * in application code and production views.
  8. Functions on indexed columns in WHERE (WHERE lower(email) = ... without an expression index).
  9. Huge OFFSET pagination.
  10. Running UPDATE/DELETE without a transaction or a WHERE you tested as a SELECT first.
  11. Never testing backups.

FAQ

How long does it take to learn SQL? Basic querying: 2-3 weeks. Comfortable with joins, aggregation and window functions: 2-3 months. Designing and tuning databases well: a year or more of real use.

Is SQL hard to learn? The syntax is small. The hard parts are thinking in sets instead of loops, handling NULLs, and understanding performance.

Which SQL should I learn first: MySQL, PostgreSQL or SQL Server? PostgreSQL is the best general pick. Core SQL transfers across all of them; dialect differences (date functions, LIMIT vs TOP, upsert syntax) take days to learn.

Is SQL still relevant with AI tools that write queries? Yes. AI tools generate SQL quickly, but you need to verify correctness (joins that double count, NULL handling) and performance. Knowing SQL well makes AI assistance safer and faster.

Do I need to learn NoSQL too? Eventually, for context: document stores (MongoDB), key-value (Redis), wide-column and graph databases. Learn relational databases first; many “NoSQL” needs are met by Postgres JSONB.

SQL for data analysis vs SQL for development: what’s different? Analysts focus on reading data (aggregation, window functions, warehouses). Developers also design schemas, write data safely, and tune for many concurrent users.

Should I get a SQL certification? Not required for most jobs. A portfolio of real queries and projects counts more. Vendor certifications can help for DBA roles in enterprises using that vendor.

What’s the difference between SQL and a database? SQL is the language; a database management system (PostgreSQL, MySQL, SQLite) stores the data and executes SQL.


Where to go next


Contributing

Corrections and suggestions are welcome via issues or pull requests. Please link only to legal, official or author-hosted resources, mark paid resources as paid, and explain in one line why a resource belongs.

If this helped you, a star helps others find it.

License

Content licensed under CC BY 4.0.

More free resources

Part of the Ralpberry Labs open-source collection. See also Top 100 Open Source.