SQL Interview Prep icon

SQL Interview Prep

SQLDataDatabaseInterviewCareer

Ace your SQL technical interview — joins, window functions, CTEs, query optimization and classic interview problems.

🤖 AI-Powered📚 30 courses👥 100,000+ learners⭐ 4.9 rating
Course Overview

Crack the SQL Interview, From Fundamentals to Window Functions

SQL is the single most tested skill in data, analytics, and backend interviews — yet most candidates stumble on the same traps: silent NULL behavior, joins that multiply rows, and the window-function questions that now show up at almost every company. This track turns interview SQL into a repeatable skill. You work through the exact question patterns asked at product and data-heavy companies, writing and running real queries against sample tables until each pattern becomes second nature.

What You Will Learn

You start with the fundamentals interviewers screen on — SELECT, column expressions, WHERE filtering gotchas, ORDER BY with LIMIT, and aggregate functions. From there you master every join type and the GROUP BY / HAVING traps that catch most candidates, plus correct NULL handling. The core of the track is the material that decides offers: subqueries and correlated subqueries, CTEs and recursive CTEs, and window functions including ROW_NUMBER, RANK, LAG/LEAD, running totals, top-N per group, and the classic Nth-highest-salary puzzles. Advanced courses cover gaps and islands, streaks, pivoting, cohort and retention analysis, funnel and A/B-test queries, query optimization with EXPLAIN, indexing strategy, transactions and isolation levels, and schema design with full mock interviews.

The Learning Path

Thirty courses progress from A1 through B2. The first two are free and cover SQL fundamentals and SELECT basics. The A1–A2 courses build the foundation — filtering, sorting, aggregation, every join type, grouping, and NULL handling. The ten B1 courses move into mid-level interview territory: subqueries, CTEs, and the full window-function toolkit modern interviews rely on. The ten B2 courses tackle senior-level analytical SQL — gaps and islands, streak and cohort analysis, funnel and A/B-test queries, performance tuning, indexing, transactions, and schema design, closing with full mock interview sessions.

How It Works

Each course is split into short, hands-on lessons you complete in the built-in editor with real-time feedback and an AI tutor on hand when you get stuck. You write and run actual queries against realistic tables — not multiple-choice trivia — so every lesson rehearses the way you will be asked to think out loud in the real interview.

Start Learning →

How You'll Learn

🎯
Interactive Lessons
Hands-on coding exercises with real-time feedback
🤖
AI Tutor
Get instant help from our AI when you're stuck
💻
Built-in Editor
Write and run code directly in your browser
🏆
Certificate
Earn a certificate when you complete the course
Curriculum

30 Courses

Every course in the SQL Interview Prep learning path.

01

SQL Fundamentals Interview Questions

A14 lessons

The most-asked SQL basics that screen out candidates in the first five minutes of an interview. Master what SQL is, how queries execute, an…

  • What Is SQL and Why Interviewers Ask It
  • Logical Query Execution Order
  • Primary Keys, Foreign Keys and Constraints
  • +1 more
02

SELECT and Column Expression Basics

A14 lessons

Interview drills on projecting columns, aliasing, computed expressions, and DISTINCT. Covers the subtle scoping rules that trip up juniors.

  • Projecting Columns and Aliasing Pitfalls
  • Computed Columns and Expression Precedence
  • DISTINCT vs GROUP BY for Uniqueness
  • +1 more
03

WHERE Clause Filtering Gotchas

A14 lessonsPRO

Classic filtering interview traps: operator precedence, BETWEEN boundaries, IN vs OR, and pattern matching. Learn why a filter that looks r…

  • AND/OR Precedence and Parenthesization
  • BETWEEN, IN, and Inclusive Boundaries
  • LIKE, Wildcards and Escaping
  • +1 more
04

ORDER BY, LIMIT and Top-N Questions

A14 lessonsPRO

Sorting and pagination interview questions, including stable ordering, multi-key sorts, and the cross-dialect way to fetch the top N rows.

  • Multi-Column Sorting and NULL Placement
  • LIMIT, OFFSET and FETCH FIRST
  • Returning the Top-N Rows Reliably
  • +1 more
05

Aggregate Functions Interview Drills

A14 lessonsPRO

COUNT, SUM, AVG, MIN, MAX and their NULL behavior under interview scrutiny. The difference between COUNT(*) and COUNT(column) is a guarante…

  • COUNT(*) vs COUNT(column) vs COUNT(DISTINCT)
  • SUM and AVG with NULLs
  • MIN, MAX and Non-Numeric Aggregation
  • +1 more
06

Introduction to INNER JOIN

A24 lessonsPRO

The join interviewers ask first. Build a precise mental model of how INNER JOIN matches rows, multiplies on duplicates, and where the ON pr…

  • How INNER JOIN Matches Rows
  • ON vs WHERE in Joins
  • Join Fan-Out and Row Multiplication
  • +1 more
07

LEFT, RIGHT and FULL OUTER JOINs

A24 lessonsPRO

Outer join interview questions: preserving unmatched rows, finding missing records, and the anti-join pattern interviewers love.

  • LEFT JOIN and Preserving Unmatched Rows
  • RIGHT and FULL OUTER JOIN Semantics
  • Finding Rows With No Match (Anti-Join)
  • +1 more
08

CROSS JOIN, SELF JOIN and Join Patterns

A24 lessonsPRO

The joins that surprise candidates. Master Cartesian products, joining a table to itself, and recognizing which join a problem really needs.

  • CROSS JOIN and Cartesian Products
  • SELF JOIN for Hierarchies
  • Comparing Rows Within One Table
  • +1 more
09

GROUP BY and HAVING Interview Traps

A24 lessonsPRO

Grouping is where interviews separate juniors from mid-levels. Learn the GROUP BY rules, HAVING vs WHERE, and the non-aggregated-column err…

  • The GROUP BY Rule for SELECT Columns
  • HAVING vs WHERE
  • Grouping by Multiple Columns and Expressions
  • +1 more
10

NULL Handling Interview Questions

A24 lessonsPRO

NULL is the number one source of wrong answers in SQL interviews. Master three-valued logic, NULL-safe comparisons, and COALESCE.

  • Three-Valued Logic and UNKNOWN
  • IS NULL, IS NOT NULL and NULL-Safe Equality
  • COALESCE, NULLIF and ISNULL
  • +1 more
11

Subqueries Deep Dive

B14 lessonsPRO

Scalar, row, and table subqueries as interviewers present them. Know where each can appear and when a subquery is the cleanest answer.

  • Scalar Subqueries in SELECT and WHERE
  • Subqueries in the FROM Clause (Derived Tables)
  • IN, ANY and ALL Subqueries
  • +1 more
12

Correlated Subqueries

B14 lessonsPRO

The subquery that runs once per outer row. Recognizing, writing, and rewriting correlated subqueries is a core mid-level interview skill.

  • Anatomy of a Correlated Subquery
  • Per-Group Aggregates Without GROUP BY
  • Correlated EXISTS and NOT EXISTS
  • +1 more
13

Common Table Expressions (CTEs)

B14 lessonsPRO

WITH clauses for readable, reusable query logic. Interviewers expect you to refactor nested subqueries into clean CTEs.

  • Writing Your First CTE
  • Chaining Multiple CTEs
  • CTE vs Subquery vs Temp Table
  • +1 more
14

Recursive CTEs and Hierarchies

B14 lessonsPRO

Recursive WITH for tree and graph traversal. Org charts, bill-of-materials, and number-series generation are staple advanced questions.

  • Anchor and Recursive Members
  • Traversing an Org Chart
  • Generating Number and Date Series
  • +1 more
15

Window Functions: ROW_NUMBER, RANK, DENSE_RANK

B14 lessonsPRO

Ranking window functions, the most-tested advanced SQL topic in interviews. Understand the difference the three ranking functions produce o…

  • OVER, PARTITION BY and ORDER BY
  • ROW_NUMBER for Unique Sequencing
  • RANK vs DENSE_RANK on Ties
  • +1 more
16

Window Functions: LAG, LEAD and NTILE

B14 lessonsPRO

Offset and bucketing window functions for comparing rows and distributing data into tiers. Period-over-period change is a guaranteed analys…

  • LAG and LEAD for Adjacent Rows
  • Period-Over-Period Change
  • NTILE for Bucketing
  • +1 more
17

Running Totals and Moving Averages

B14 lessonsPRO

Window frame clauses for cumulative and rolling calculations. ROWS vs RANGE framing is a precise mid-level distinction interviewers probe.

  • Cumulative Sums With Window Frames
  • ROWS vs RANGE Framing
  • Moving Averages Over a Sliding Window
  • +1 more
18

Top-N per Group and Deduplication

B14 lessonsPRO

Two of the highest-frequency interview problems solved cleanly with window functions: top item per category and removing duplicate rows.

  • Top-N Rows Per Group With ROW_NUMBER
  • Handling Ties in Top-N
  • Deduplicating Rows Safely
  • +1 more
19

Nth Highest Salary and Ranking Puzzles

B14 lessonsPRO

The interview question every candidate gets: second highest salary, then Nth highest, with all the edge cases interviewers add.

  • Second Highest Salary, Five Ways
  • Nth Highest With DENSE_RANK
  • Per-Department Top Earner
  • +1 more
20

Set Operations: UNION, INTERSECT, EXCEPT

B14 lessonsPRO

Combining result sets correctly. UNION vs UNION ALL, column compatibility rules, and using set operations to compare datasets.

  • UNION vs UNION ALL
  • Column Count and Type Compatibility
  • INTERSECT and EXCEPT for Comparison
  • +1 more
21

Gaps and Islands Problems

B24 lessonsPRO

The advanced pattern-recognition problem class: finding consecutive runs and the gaps between them. A senior-level signal in SQL interviews.

  • Recognizing a Gaps-and-Islands Problem
  • The Row-Number Difference Trick
  • Finding Gaps in a Sequence
  • +1 more
22

Consecutive Days and Streak Analysis

B24 lessonsPRO

Streak and run-length problems: consecutive login days, winning streaks, and the LeetCode-style three-consecutive-rows question.

  • Detecting Consecutive Calendar Days
  • Longest Streak Per User
  • N Consecutive Rows Meeting a Condition
  • +1 more
23

Pivot and Unpivot Techniques

B24 lessonsPRO

Reshaping data between long and wide form. Conditional aggregation pivots and the reverse unpivot are common reporting-interview asks.

  • Pivoting With Conditional Aggregation
  • Vendor PIVOT and Crosstab Syntax
  • Unpivoting Columns Into Rows
  • +1 more
24

Date, Time and String Interview Questions

B24 lessonsPRO

Date arithmetic, truncation, and string manipulation as posed in interviews, with cross-dialect awareness of function names.

  • Date Arithmetic and Intervals
  • Truncating and Bucketing Dates
  • Parsing and Formatting Strings
  • +1 more
25

Cohort and Retention Analysis SQL

B24 lessonsPRO

Product-analytics interview queries: building cohorts, computing retention curves, and the self-join versus window approaches.

  • Defining a Cohort by First Action
  • Building a Retention Matrix
  • Day-N and Rolling Retention
  • +1 more
26

Funnel and A/B Test Analysis SQL

B24 lessonsPRO

Event-funnel conversion and experiment-analysis queries that data-analyst interviews lean on heavily.

  • Building a Multi-Step Funnel
  • Ordered Events and Time Windows
  • A/B Test Assignment and Metrics
  • +1 more
27

Query Optimization and EXPLAIN

B24 lessonsPRO

Reading execution plans and explaining why a query is slow, the senior differentiator in technical interviews.

  • Reading an EXPLAIN Plan
  • Seq Scan vs Index Scan vs Index-Only
  • Join Algorithms: Nested Loop, Hash, Merge
  • +1 more
28

Indexing Strategy Questions

B24 lessonsPRO

Index design as interviewers test it: which columns to index, composite order, covering indexes, and when indexes hurt.

  • B-Tree Indexes and How They Help
  • Composite Index Column Order
  • Covering Indexes and Index-Only Scans
  • +1 more
29

Transactions, ACID and Isolation Levels

B24 lessonsPRO

Concurrency interview questions: ACID guarantees, the four isolation levels, and the anomalies each prevents.

  • ACID Properties Explained
  • The Four Isolation Levels
  • Dirty, Non-Repeatable and Phantom Reads
  • +1 more
30

Schema Design, Normalization and Mock Interviews

B24 lessonsPRO

Capstone course on database modeling and a set of full mock interview problems. Normalization, star schemas, and end-to-end problem solving.

  • Normalization Through 3NF
  • ER Modeling and Relationship Cardinality
  • Star Schema and Data Warehouse Design
  • +1 more
FAQ

Frequently Asked Questions

Is the SQL Interview Prep course free?

Yes. You can start the SQL Interview Prep course for free and complete its interactive lessons at no cost. An optional PRO subscription unlocks advanced AI tools and a shareable certificate.

Do I need prior experience to learn SQL?

No. The course begins with the fundamentals and gradually moves to more advanced topics, so you can start even with no prior SQL experience.

How will I learn SQL on CoddyKit?

You learn by doing. Short interactive lessons pair a clear explanation with a hands-on coding exercise that runs in real time, and a 24/7 AI tutor gives personalized help whenever you get stuck.

Do I get a certificate for completing SQL Interview Prep?

Yes. PRO learners can take an exam and earn a shareable certificate of completion with a verifiable code for the SQL Interview Prep course.

Can I learn SQL on my phone?

Yes. CoddyKit is available on the web and as native iOS and Android apps, so you can learn SQL on any device and your progress syncs across them.

Start SQL Interview Prep Now

Join thousands of learners mastering programming with AI-powered lessons.

Get Started Free →Browse All Courses