Ask questions of data

SQL

The language of relational databases. Everything here runs on a real SQLite engine inside your browser: every tutorial example was executed before publishing and opens in the playground with one click, and every exercise is checked by running your query against a sample database.

Beginner-friendlyRuns in your browser
tutorials
32 tutorials
exercises
42 exercises
glossary terms
45 glossary terms
interview questions
25 interview questions

What SQL is used for

  • Data analysis and reporting
  • Backend development
  • Data engineering and pipelines
  • Analyst and data-science interviews

Dialects

The engine is SQLite. Where MySQL, PostgreSQL or SQL Server differ, the tutorials say so and label vendor-specific syntax instead of passing it off as standard. See the dialect guide.

Twelve steps

The learning path

New to SQL? Follow the numbers. Read a step, then cement it with the matching practice exercises. Everything stays open in any order.

  1. First queriesTables, SELECT, your first results
  2. FilteringWHERE, operators, NULL
  3. JOINsCombining related tables
  4. AggregationGROUP BY, HAVING, COUNT and SUM
  5. Changing dataINSERT, UPDATE, DELETE — safely
  6. SubqueriesQueries inside queries
  7. CASE logicConditional values and reports
  8. CTEsMulti-step queries with WITH
  9. Text functionsUPPER, SUBSTRING, TRIM, REPLACE
  10. Date functionsYEAR, MONTH, ranges, DATEDIFF
  11. Window functionsROW_NUMBER, RANK, PARTITION BY
  12. Interview prepQuestions and real scenarios

32 guides

All SQL tutorials

Every guide on the site, in the order the course reads them. Each has runnable examples with their real output, a FAQ and a practice section.

  1. How to Write SQL Queries: A Complete Beginner's GuideNever written SQL before? This step-by-step guide starts from zero — what a table is, your first query, filtering, sorting, and more — with examples you can run instantly.
  2. The SQL SELECT Statement: A Beginner's GuideLearn the SQL SELECT statement from scratch: column lists, aliases, DISTINCT, ORDER BY, and LIMIT, with examples you can run instantly in the browser.
  3. The SQL WHERE Clause: Filtering Data with Every OperatorA complete guide to the SQL WHERE clause: comparison operators, AND/OR/NOT, IN, BETWEEN, LIKE, and IS NULL, with runnable examples.
  4. SQL JOINs Explained: INNER, LEFT, RIGHT & FULLA clear, table-by-table walkthrough of INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL OUTER JOIN in SQL, with runnable examples.
  5. GROUP BY vs HAVING in SQL: What's the Difference?The clear, memorable explanation of GROUP BY vs HAVING in SQL, why WHERE can't filter aggregates, and worked examples.
  6. SQL INSERT, UPDATE, DELETE: Changing Data SafelyHow to add, change and remove rows in SQL — and the SELECT-first habit that stops a missing WHERE clause from destroying a table. Runnable examples included.
  7. SQL Subqueries Explained: Nested SELECT StatementsScalar, row, and correlated subqueries in SQL explained with examples, plus when a JOIN is the better tool instead.
  8. SQL CASE WHEN Explained: Conditional Logic in QueriesHow SQL CASE expressions work: searched vs simple CASE, custom sort orders, counting and summing by condition — with runnable examples.
  9. SQL CTEs Explained: How the WITH Clause WorksWhat a Common Table Expression is, why WITH beats nested subqueries for readable multi-step queries, and how to chain several CTEs — with runnable examples.
  10. SQL String Functions: UPPER, SUBSTRING, TRIM & MoreThe core SQL string functions — UPPER, LOWER, LENGTH, SUBSTRING, REPLACE, TRIM, CONCAT, COALESCE and NULLIF — explained with runnable examples and dialect notes.
  11. SQL Date Functions: YEAR, MONTH, DATEDIFF & RangesThe date functions real queries use: YEAR, MONTH, DATEDIFF, today's date, adding days, month starts and the safe date-range pattern. Runnable SQLite examples, other dialects alongside.
  12. SQL Window Functions: ROW_NUMBER, RANK & PARTITION BYWhat window functions do, how ROW_NUMBER, RANK, DENSE_RANK and PARTITION BY differ, and the top-N-per-group pattern interviews often ask for.
  13. 25 SQL Interview Questions and Answers25 commonly asked SQL interview questions with clear answers — from WHERE vs HAVING to window functions, normalization, and finding duplicate rows.
  14. SQL Scenario Questions for Data Analyst InterviewsTen business-scenario SQL questions of the kind data analyst interviews actually ask, each with a runnable solution and the reasoning an interviewer wants to hear.
  15. SQL Cheat Sheet: Core Syntax, Joins and Functions on One PageA free one-page SQL cheat sheet: execution order, SELECT, WHERE, JOINs, GROUP BY, subqueries, CTEs, set operators, window functions, string and date functions, and NULL rules.
  16. SQL Exercises with Solutions: 15 Practice ProblemsFifteen SQL practice problems with full solutions and explanations, from a first SELECT to multi-step reports. Every solution runs on a live sample database you can open in one click.
  17. PostgreSQL vs MySQL vs SQL Server vs SQLite: SQL Syntax DifferencesThe SQL differences that actually bite when you switch databases: LIMIT vs TOP, quoting, string concatenation, dates, booleans, auto-increment keys, upserts and window-function support, side by side.
  18. SQL for Data Analysts: The Queries You Actually WriteThe SQL a working data analyst uses every day: filtering, grouping, joins, conditional aggregation, trends and running totals - with runnable examples and the mistakes that quietly corrupt reports.
  19. How to Find the Second Highest Salary in SQL (5 Ways)Five ways to find the second highest salary in SQL - subquery, LIMIT OFFSET, correlated count, DENSE_RANK and CTE - plus the Nth highest and ties.
  20. Find and Delete Duplicate Rows in SQLFind duplicate rows in SQL with GROUP BY and HAVING, see every copy rather than the counts, and delete the extras while keeping one - safely.
  21. SQL Aggregate Functions: COUNT, SUM, AVG, MIN and MAXCOUNT, SUM, AVG, MIN and MAX with runnable examples: COUNT(*) vs COUNT(column), how NULLs are skipped, and why WHERE cannot filter an aggregate.
  22. SQL ORDER BY and LIMIT: Sorting, Top-N and PaginationHow ORDER BY sorts - several columns, expressions, aliases, NULL placement - and how LIMIT with OFFSET gives you top-N results and pagination.
  23. SELECT DISTINCT in SQL: Removing Duplicate Rows from ResultsHow SELECT DISTINCT works, why it applies to the whole row and not one column, DISTINCT with several columns, COUNT(DISTINCT), and when GROUP BY is the better tool.
  24. UNION vs UNION ALL in SQL: Which One and WhyUNION removes duplicate rows and UNION ALL keeps them. What that costs, the column rules both must obey, where ORDER BY goes, and why UNION ALL is the right default.
  25. EXISTS vs IN in SQL: Which to Use and WhenHow EXISTS and IN differ, why NOT IN breaks on NULL while NOT EXISTS does not, when a JOIN is better than either, and how to choose - with runnable examples.
  26. DELETE vs TRUNCATE vs DROP in SQL: The Real DifferenceDELETE removes chosen rows, TRUNCATE empties a table, DROP removes the table. What each logs and resets, which can be rolled back, and how to choose.
  27. SQL Commands: DDL, DML, DCL and TCL ExplainedEvery SQL statement belongs to one of four families - DDL, DML, DCL and TCL. What each does, which can be rolled back, and why implicit commits matter.
  28. SQL Constraints: NOT NULL, UNIQUE, CHECK, DEFAULT and KeysNOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK and DEFAULT explained with the exact errors they produce - and why they belong in the database.
  29. Primary Key vs Foreign Key in SQL: The Difference ExplainedA primary key identifies a row; a foreign key points at one. How they differ in uniqueness, NULLs and count - plus composite keys and ON DELETE.
  30. Database Normalization: 1NF, 2NF and 3NF with ExamplesNormalization explained by fixing one badly designed table step by step - first normal form, second, third - plus what denormalization is for and when to stop.
  31. SQL Views: CREATE VIEW, When to Use One, and What It CostsWhat a view is, how CREATE VIEW works, why it does not make queries faster, when a view is updatable, and how a materialized view differs - with runnable examples.
  32. SQL Indexes: How They Speed Up Queries (and What They Cost)What an index actually is, how CREATE INDEX works, which columns to index, why composite column order matters, and the mistakes that stop an index being used at all.

Reference and preparation

More SQL