Menu

Course · Languages & query

SQL for Data Engineers

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
30
Projects & case studies
13
Reading time
~8 h

Your progress

Saved in this browser only

Course structure

Practise

Practice

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

Core SQL interview questions0/9
  1. Explain INNER JOIN vs LEFT JOIN with a practical example.EasyDataDank only
  2. Find customers who never placed an order, and explain NOT IN vs NOT EXISTS.EasyLeetCode (opens in a new tab)
  3. How do window functions differ from GROUP BY?EasyDataDank only
  4. Find the second-highest salary without using a simple MAX approach.MediumLeetCode (opens in a new tab)
  5. How would you detect and remove duplicate records safely?MediumLeetCode (opens in a new tab)
  6. Return the top three salaries in each department, including ties.MediumLeetCode (opens in a new tab)
  7. Revenue doubled after you joined a second table. What happened and how do you fix it?MediumDataDank only
  8. How would you optimize a slow analytical SQL query?HardDataDank only
  9. Write an SCD Type 2 upsert in SQL that closes old versions and inserts new ones.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 LIMITSQL fundamentals: SELECT and WHERE, aliases, DISTINCT, multi-column ORDER BY and LIMIT, plus TOP and FETCH FIRST in 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 EXCEPTSQL UNION, UNION ALL, INTERSECT and EXCEPT explained: how duplicates and NULLs are handled, column matching rules and data reconciliation patterns.Beginner12 min
  5. SQL Joins: INNER, LEFT, RIGHT, FULL, Self and Cross JoinsSQL joins explained: INNER, LEFT, RIGHT and FULL OUTER, self and cross joins, multi-table joins, and how to predict row counts and avoid fan-out traps.Beginner25 min

Intermediate

Patterns used in production pipelines.

  1. Semi-Joins, Anti-Joins and LATERAL Joins in SQLSQL semi and anti joins: use EXISTS and NOT EXISTS to avoid duplicate rows, dodge the NOT IN NULL trap, and use LATERAL or CROSS APPLY for per-row top-N.Intermediate17 min
  2. SQL Subqueries and CTEs: Derived Tables, Correlated Queries and Temporary TablesSQL CTEs and subqueries: write them in WHERE, FROM and SELECT, understand correlated subqueries, chain CTEs, and know when a temp 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_VALUESQL window functions: OVER and PARTITION BY, ROW_NUMBER, RANK and DENSE_RANK with ties, NTILE buckets, LAG and LEAD, and FIRST_VALUE and LAST_VALUE.Intermediate18 min
  5. Window Frames: Running Totals, Moving Averages and PercentilesSQL window frames: running totals, moving averages with ROWS and RANGE, conditional window aggregates, percent of total, CUME_DIST and PERCENTILE_CONT median.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 QueriesThree SQL pipeline patterns: 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 AttributionSQL retention and cohort analysis: day-N retention, cohort matrices, ordered funnels, first and last touch attribution and market basket lift queries.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 DistinctSQL performance at scale: tune window functions, fix skewed keys with two-phase aggregation and salting, and count distinct values with HyperLogLog.Advanced18 min
  10. Transactions, Isolation Levels, Locking and MVCCSQL transactions and isolation levels: ACID, the anomalies each level allows, row locks and deadlocks, and how MVCC lets readers and writers run together.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