Menu

Course · Languages & query

SQL for Data Engineers

Free SQL course for Data Engineers: joins, window functions, CTEs, deduplication, SCD queries and query plans, with runnable examples and interview questions.

Lessons
26
Interview questions
34
Projects & case studies
13
Reading time
~10 h

Your progress

Saved in this browser only

Course structure

Practise

Practice

137 problems in 13 topics, from basic to advanced. 29 have a full DataDank answer; 108 more are free problems on LeetCode and DataLemur that open on the platform. 0 of 137 done.

DataDank answers with a LeetCode problem0/4
  1. Find customers who never placed an order, and explain NOT IN vs NOT EXISTS.EasyLeetCode (opens in a new tab)
  2. Find the second-highest salary without using a simple MAX approach.MediumLeetCode (opens in a new tab)
  3. How would you detect and remove duplicate records safely?MediumLeetCode (opens in a new tab)
  4. Return the top three salaries in each department, including ties.MediumLeetCode (opens in a new tab)
LeetCode SQL 50: Select and filter0/5
  1. 1757. Recyclable and Low Fat Products (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
  2. 584. Find Customer Referee (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
  3. 595. Big Countries (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
  4. 1148. Article Views I (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
  5. 1683. Invalid Tweets (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
LeetCode SQL 50: Joins0/10
  1. 175. Combine Two Tables (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
  2. 1378. Replace Employee ID With The Unique Identifier (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
  3. 1068. Product Sales Analysis I (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
  4. 1581. Customer Who Visited but Did Not Make Any Transactions (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
  5. 197. Rising Temperature (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
  6. 1661. Average Time of Process per Machine (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
  7. 577. Employee Bonus (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
  8. 1280. Students and Examinations (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
  9. 570. Managers with at Least 5 Direct Reports (opens LeetCode in a new tab)MediumLeetCode (opens in a new tab)
  10. 1934. Confirmation Rate (opens LeetCode in a new tab)MediumLeetCode (opens in a new tab)
LeetCode SQL 50: Aggregate functions0/8
  1. 620. Not Boring Movies (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
  2. 1251. Average Selling Price (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
  3. 1075. Project Employees I (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
  4. 1633. Percentage of Users Attended a Contest (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
  5. 1211. Queries Quality and Percentage (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
  6. 1193. Monthly Transactions I (opens LeetCode in a new tab)MediumLeetCode (opens in a new tab)
  7. 1174. Immediate Food Delivery II (opens LeetCode in a new tab)MediumLeetCode (opens in a new tab)
  8. 550. Game Play Analysis IV (opens LeetCode in a new tab)MediumLeetCode (opens in a new tab)
LeetCode SQL 50: Sorting and grouping0/9
  1. 2356. Number of Unique Subjects Taught by Each Teacher (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
  2. 1141. User Activity for the Past 30 Days I (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
  3. 596. Classes More Than 5 Students (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
  4. 1729. Find Followers Count (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
  5. 619. Biggest Single Number (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
  6. 586. Customer Placing the Largest Number of Orders (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
  7. 182. Duplicate Emails (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
  8. 1070. Product Sales Analysis III (opens LeetCode in a new tab)MediumLeetCode (opens in a new tab)
  9. 1045. Customers Who Bought All Products (opens LeetCode in a new tab)MediumLeetCode (opens in a new tab)
LeetCode SQL 50: Advanced select and joins0/8
  1. 1731. The Number of Employees Which Report to Each Employee (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
  2. 1789. Primary Department for Each Employee (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
  3. 610. Triangle Judgment (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
  4. 180. Consecutive Numbers (opens LeetCode in a new tab)MediumLeetCode (opens in a new tab)
  5. 1164. Product Price at a Given Date (opens LeetCode in a new tab)MediumLeetCode (opens in a new tab)
  6. 1204. Last Person to Fit in the Bus (opens LeetCode in a new tab)MediumLeetCode (opens in a new tab)
  7. 1907. Count Salary Categories (opens LeetCode in a new tab)MediumLeetCode (opens in a new tab)
  8. 262. Trips and Users (opens LeetCode in a new tab)HardLeetCode (opens in a new tab)
LeetCode SQL 50: Subqueries0/9
  1. 1978. Employees Whose Manager Left the Company (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
  2. 1084. Sales Analysis III (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
  3. 626. Exchange Seats (opens LeetCode in a new tab)MediumLeetCode (opens in a new tab)
  4. 1341. Movie Rating (opens LeetCode in a new tab)MediumLeetCode (opens in a new tab)
  5. 1321. Restaurant Growth (opens LeetCode in a new tab)MediumLeetCode (opens in a new tab)
  6. 602. Friend Requests II: Who Has the Most Friends (opens LeetCode in a new tab)MediumLeetCode (opens in a new tab)
  7. 585. Investments in 2016 (opens LeetCode in a new tab)MediumLeetCode (opens in a new tab)
  8. 184. Department Highest Salary (opens LeetCode in a new tab)MediumLeetCode (opens in a new tab)
  9. 1158. Market Analysis I (opens LeetCode in a new tab)MediumLeetCode (opens in a new tab)
LeetCode SQL 50: Strings, dates and regex0/5
  1. 1667. Fix Names in a Table (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
  2. 1527. Patients With a Condition (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
  3. 1484. Group Sold Products By The Date (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
  4. 1327. List the Products Ordered in a Period (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
  5. 1517. Find Users With Valid E-Mails (opens LeetCode in a new tab)EasyLeetCode (opens in a new tab)
DataLemur: easy interview questions0/21
  1. Histogram of Tweets (opens DataLemur in a new tab)EasyDataLemur (opens in a new tab)
  2. Data Science Skills (opens DataLemur in a new tab)EasyDataLemur (opens in a new tab)
  3. Page With No Likes (opens DataLemur in a new tab)EasyDataLemur (opens in a new tab)
  4. Unfinished Parts (opens DataLemur in a new tab)EasyDataLemur (opens in a new tab)
  5. Laptop vs. Mobile Viewership (opens DataLemur in a new tab)EasyDataLemur (opens in a new tab)
  6. Average Post Hiatus (Part 1) (opens DataLemur in a new tab)EasyDataLemur (opens in a new tab)
  7. Teams Power Users (opens DataLemur in a new tab)EasyDataLemur (opens in a new tab)
  8. Duplicate Job Listings (opens DataLemur in a new tab)EasyDataLemur (opens in a new tab)
  9. Cities With Completed Trades (opens DataLemur in a new tab)EasyDataLemur (opens in a new tab)
  10. Average Review Ratings (opens DataLemur in a new tab)EasyDataLemur (opens in a new tab)
  11. Well Paid Employees (opens DataLemur in a new tab)EasyDataLemur (opens in a new tab)
  12. Final Account Balance (opens DataLemur in a new tab)EasyDataLemur (opens in a new tab)
  13. App Click-through Rate (CTR) (opens DataLemur in a new tab)EasyDataLemur (opens in a new tab)
  14. Second Day Confirmation (opens DataLemur in a new tab)EasyDataLemur (opens in a new tab)
  15. IBM db2 Product Analytics (opens DataLemur in a new tab)EasyDataLemur (opens in a new tab)
  16. Cards Issued Difference (opens DataLemur in a new tab)EasyDataLemur (opens in a new tab)
  17. Compressed Mean (opens DataLemur in a new tab)EasyDataLemur (opens in a new tab)
  18. Pharmacy Analytics (Part 1) (opens DataLemur in a new tab)EasyDataLemur (opens in a new tab)
  19. Pharmacy Analytics (Part 2) (opens DataLemur in a new tab)EasyDataLemur (opens in a new tab)
  20. Pharmacy Analytics (Part 3) (opens DataLemur in a new tab)EasyDataLemur (opens in a new tab)
  21. Patient Support Analysis (Part 1) (opens DataLemur in a new tab)EasyDataLemur (opens in a new tab)
DataLemur: medium interview questions0/19
  1. User's Third Transaction (opens DataLemur in a new tab)MediumDataLemur (opens in a new tab)
  2. Second Highest Salary (opens DataLemur in a new tab)MediumDataLemur (opens in a new tab)
  3. Sending vs. Opening Snaps (opens DataLemur in a new tab)MediumDataLemur (opens in a new tab)
  4. Tweets' Rolling Averages (opens DataLemur in a new tab)MediumDataLemur (opens in a new tab)
  5. Highest-Grossing Items (opens DataLemur in a new tab)MediumDataLemur (opens in a new tab)
  6. Top Three Salaries (opens DataLemur in a new tab)MediumDataLemur (opens in a new tab)
  7. Signup Activation Rate (opens DataLemur in a new tab)MediumDataLemur (opens in a new tab)
  8. Spotify Streaming History (opens DataLemur in a new tab)MediumDataLemur (opens in a new tab)
  9. Supercloud Customer (opens DataLemur in a new tab)MediumDataLemur (opens in a new tab)
  10. Odd and Even Measurements (opens DataLemur in a new tab)MediumDataLemur (opens in a new tab)
  11. Swapped Food Delivery (opens DataLemur in a new tab)MediumDataLemur (opens in a new tab)
  12. FAANG Stock Min-Max (Part 1) (opens DataLemur in a new tab)MediumDataLemur (opens in a new tab)
  13. Best-Selling Product (opens DataLemur in a new tab)MediumDataLemur (opens in a new tab)
  14. User Shopping Sprees (opens DataLemur in a new tab)MediumDataLemur (opens in a new tab)
  15. Histogram of Users and Purchases (opens DataLemur in a new tab)MediumDataLemur (opens in a new tab)
  16. Compressed Mode (opens DataLemur in a new tab)MediumDataLemur (opens in a new tab)
  17. Card Launch Success (opens DataLemur in a new tab)MediumDataLemur (opens in a new tab)
  18. International Call Percentage (opens DataLemur in a new tab)MediumDataLemur (opens in a new tab)
  19. Patient Support Analysis (Part 2) (opens DataLemur in a new tab)MediumDataLemur (opens in a new tab)
DataLemur: hard interview questions0/14
  1. Active User Retention (opens DataLemur in a new tab)HardDataLemur (opens in a new tab)
  2. Y-on-Y Growth Rate (opens DataLemur in a new tab)HardDataLemur (opens in a new tab)
  3. Maximize Prime Item Inventory (opens DataLemur in a new tab)HardDataLemur (opens in a new tab)
  4. Median Google Search Frequency (opens DataLemur in a new tab)HardDataLemur (opens in a new tab)
  5. Advertiser Status (opens DataLemur in a new tab)HardDataLemur (opens in a new tab)
  6. Consecutive Filing Years (opens DataLemur in a new tab)HardDataLemur (opens in a new tab)
  7. Marketing Touch Streak (opens DataLemur in a new tab)HardDataLemur (opens in a new tab)
  8. 3-Topping Pizzas (opens DataLemur in a new tab)HardDataLemur (opens in a new tab)
  9. Patient Support Analysis (Part 3) (opens DataLemur in a new tab)HardDataLemur (opens in a new tab)
  10. Patient Support Analysis (Part 4) (opens DataLemur in a new tab)HardDataLemur (opens in a new tab)
  11. Repeated Payments (opens DataLemur in a new tab)HardDataLemur (opens in a new tab)
  12. Reactivated Users (opens DataLemur in a new tab)HardDataLemur (opens in a new tab)
  13. Senior Managers (opens DataLemur in a new tab)HardDataLemur (opens in a new tab)
  14. Server Utilization Time (opens DataLemur in a new tab)HardDataLemur (opens in a new tab)
Core SQL questions (DataDank only)0/9
  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. In what order is a SQL query evaluated, and what is the difference between WHERE and HAVING?EasyDataDank only
  4. Calculate month-over-month and year-over-year revenue growth in SQL.MediumDataDank only
  5. Compute a running total and a 3-day moving average of daily revenue in SQL.MediumDataDank only
  6. Revenue doubled after you joined a second table. What happened and how do you fix it?MediumDataDank only
  7. There is an index on the column, but EXPLAIN shows a sequential scan. Why?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 studies (DataDank only)0/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. What Is a Relational Database (RDBMS)? Tables, Keys and SQL ExplainedWhat a relational database is: tables, rows, primary and foreign keys, constraints, SQL and transactions, and how an RDBMS differs from NoSQL, with examples.Beginner7 min
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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_VALUEWindow functions in SQL with examples: OVER and PARTITION BY, ROW_NUMBER, RANK vs DENSE_RANK, NTILE, 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
  8. CAP Theorem, PACELC and BASE Explained for Data EngineersWhat the CAP theorem really says, why 'pick two of three' is misleading, how PACELC adds latency, and how BASE compares with ACID, with a small Python demo.Intermediate7 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

Interview preparation

The top interview questions, with answers.

  1. Top 50 SQL Interview Questions and Answers for Data Engineers50 SQL interview questions with answers and SQL code: joins, window functions, gaps and islands, deduplication and query tuning. For freshers to senior.Intermediate108 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