Menu

Course · Languages & query

SQL

SQL is the core language of data work: querying, transforming and modelling data in warehouses, lakehouses and Spark. Start here before any other tool.

Lessons
23
Interview questions
22
Projects & case studies
13
Reading time
~8 h

Your progress

Saved in this browser only

Course structure

Practise

Practice

21 problems in 2 topics, from basic to advanced. 0 of 21 done.

Core SQL interview questions0/5
  1. Explain INNER JOIN vs LEFT JOIN with a practical example.EasyDataDank only
  2. How do window functions differ from GROUP BY?EasyDataDank only
  3. Find the second-highest salary without using a simple MAX approach.MediumLeetCode (opens in a new tab)
  4. How would you detect and remove duplicate records safely?MediumLeetCode (opens in a new tab)
  5. How would you optimize a slow analytical SQL query?HardDataDank only
Business case studies0/16
  1. Average Order ValueMediumDataDank only
  2. Customer Lifetime ValueMediumDataDank only
  3. Daily Active UsersMediumDataDank only
  4. Lead ScoringMediumDataDank only
  5. New vs Returning CustomersMediumDataDank only
  6. Refund AnalysisMediumDataDank only
  7. Session DurationMediumDataDank only
  8. Subscription RenewalsMediumDataDank only
  9. Top Selling ProductsMediumDataDank only
  10. A/B Test ResultsHardDataDank only
  11. Churn RateHardDataDank only
  12. Conversion FunnelHardDataDank only
  13. Employee HierarchyHardDataDank only
  14. Fraud Pattern DetectionHardDataDank only
  15. Inventory TurnoverHardDataDank only
  16. Monthly RevenueHardDataDank only

Ticks are saved in this browser only and match the ticks on the interview pages.

Lessons

Work through the lessons in order. Completed lessons show a tick; lessons you have opened are outlined.

Start here

The complete overview of the course in one read.

  1. SQL Fundamentals: SELECT, WHERE, DISTINCT, ORDER BY and LIMITLearn the core of every SQL query: SELECT and WHERE, aliases, DISTINCT, multi-column ORDER BY and LIMIT, TOP or FETCH FIRST across PostgreSQL, MySQL and SQL Server.Beginner19 min

Beginner

Core concepts you will use every day.

  1. SQL Operators, NULL Handling and CASE ExpressionsWrite correct SQL filters: comparison and logical operators, IN, BETWEEN and LIKE, three-valued NULL logic with COALESCE and NULLIF, and CASE WHEN expressions.Beginner16 min
  2. SQL Functions: Strings, Dates, Type Casting and ArithmeticClean and convert data in SQL: string functions, date arithmetic, CAST and safe casting, integer division and rounding, with names for each major SQL dialect.Beginner20 min
  3. SQL Aggregations: GROUP BY, HAVING and Conditional AggregationHow SUM, AVG, MIN, MAX and COUNT treat NULLs, how GROUP BY sets the grain, WHERE versus HAVING, and conditional aggregation for metrics built in one pass.Beginner18 min
  4. SQL Set Operations: UNION, UNION ALL, INTERSECT and EXCEPTCombine and compare query results with UNION, UNION ALL, INTERSECT and EXCEPT: duplicate handling, NULL behaviour, column matching and data reconciliation patterns.Beginner12 min
  5. SQL Joins: INNER, LEFT, RIGHT, FULL, Self and Cross JoinsPredict the row count of any SQL join: INNER, LEFT, RIGHT and FULL OUTER joins, self joins, cross joins and multi-table joins, plus the filtering and fan-out traps.Beginner25 min

Intermediate

Patterns used in production pipelines.

  1. Semi-Joins, Anti-Joins and LATERAL Joins in SQLFilter with EXISTS and NOT EXISTS instead of joins that duplicate rows, avoid the NOT IN NULL trap, and use LATERAL or CROSS APPLY for per-row top-N and unnesting.Intermediate17 min
  2. SQL Subqueries and CTEs: Derived Tables, Correlated Queries and Temporary TablesWrite subqueries in WHERE, FROM and SELECT, understand correlated subqueries, structure logic with chained CTEs, and know when a temporary table is the better choice.Intermediate18 min
  3. PIVOT, UNPIVOT, GROUPING SETS, ROLLUP and CUBEReshape data in SQL: pivot rows to columns, unpivot columns to rows, handle dynamic pivot columns, and compute subtotals with GROUPING SETS, ROLLUP and CUBE.Intermediate19 min
  4. SQL Window Functions: Ranking, LAG/LEAD and FIRST_VALUELearn SQL window functions: OVER and PARTITION BY, ROW_NUMBER, RANK and DENSE_RANK with ties, NTILE buckets, LAG and LEAD comparisons, and FIRST_VALUE and LAST_VALUE.Intermediate18 min
  5. Window Frames: Running Totals, Moving Averages and PercentilesMaster SQL window frames: running totals, moving averages with ROWS and RANGE, conditional window aggregates, percent of total, CUME_DIST and median with PERCENTILE_CONT.Intermediate24 min
  6. Time-Series SQL: Date Buckets, Calendars, YoY, MoM and Rolling MetricsBuild time-series metrics in SQL: bucket dates, generate calendars to fill gaps, and compute month-over-month, year-over-year and rolling 7 and 30 day figures.Intermediate24 min
  7. Top-N per Group, Deduplication and SCD QueriesSolve three everyday pipeline problems in SQL: top N rows per group with ties, deduplicating to the latest record per key, and querying Type 2 slowly changing dimensions.Intermediate22 min

Advanced

Performance, internals and edge cases.

  1. Recursive CTEs: Hierarchies and Graph Traversal in SQLLearn how recursive CTEs work step by step, then use them to walk org charts, roll up hierarchies and traverse graphs safely without infinite loops.Advanced18 min
  2. Gaps and Islands, Streaks and Sessionization in SQLSolve gaps-and-islands problems with window functions: find missing values, group consecutive rows, measure streaks and split clickstreams into sessions.Advanced17 min
  3. Product Analytics SQL: Retention, Cohorts, Funnels and AttributionWrite the product analytics queries interviewers ask for: day-N retention, cohort matrices, ordered funnels, first and last touch attribution and market basket lift.Advanced18 min
  4. Semi-Structured SQL: JSON, Arrays and Regular ExpressionsParse JSON, flatten nested arrays and extract text with regular expressions in SQL, with PostgreSQL examples and the Snowflake and BigQuery equivalents.Advanced16 min
  5. SQL Query Optimization and Execution PlansA practical process for speeding up slow SQL: read EXPLAIN plans, avoid full table scans, rewrite queries for performance and spot common anti-patterns.Advanced27 min
  6. SQL Indexes: B-tree, Composite, Covering and Bitmap IndexesHow database indexes work and how to design them: B-tree and composite column order, covering indexes, selectivity and cardinality, and bitmap indexing.Advanced23 min
  7. Partitioning, Materialized Views, Columnar Storage and ShardingDesign table partitioning and check pruning in query plans, use materialized views safely, compare row and columnar storage, and choose a sharding key.Advanced24 min
  8. Inside the Query Optimizer: Join Algorithms, Statistics and MemoryHow the optimiser chooses a plan: nested loop, hash and merge joins, table statistics, cardinality estimation, CTE materialisation and spilling to disk.Advanced26 min
  9. SQL at Scale: Window Performance, Skew and Approximate DistinctKeep big queries fast: tune window functions, handle skewed keys in aggregations with two-phase aggregation and salting, and count distinct values with HyperLogLog.Advanced18 min
  10. Transactions, Isolation Levels, Locking and MVCCUnderstand ACID transactions, isolation levels and the anomalies they allow, row locks and deadlocks, and how MVCC lets readers and writers work at the same time.Advanced21 min

Projects and case studies

Apply what you learned and prepare material to discuss in interviews.

Projects

System design case studies

Resources

Cheat sheets

Related courses

Plan your learning

Search
Filter by type