SQL Quest Blog

Long-form SQL tutorials and deep-dives. Each post is opinionated, has runnable examples, and links into the practice app so the patterns actually stick. Topics expand monthly.

ROW_NUMBER vs RANK vs DENSE_RANK — the Difference Is the Tie

Real salary ties shown: RANK gives 5,5,7; DENSE_RANK 5,5,6; ROW_NUMBER forces order arbitrarily. Which each task wants, the top-N-per-group pattern, and the silent four-row bug.

Read the tie table

WHERE vs HAVING — One Rule, Four Cases, Real Row Counts

Rows before groups, groups before output. The execution order, four worked cases on real data, and the error you get when an aggregate sneaks into WHERE.

Read the rule

IS NULL vs = NULL — Why Your WHERE Returns Nothing

7 rows IS NULL, 0 rows = NULL — same table, same instant. Three-valued logic in one line, the NOT IN trap it feeds, and the COALESCE repair kit.

Read the explainer

SQL Running Total — One OVER Clause, Real Orders

SUM(x) OVER (ORDER BY …) turns a column into its cumulative sum. Per-customer with PARTITION BY, the tie trap in the default frame, and the O(n²) self-join it replaced.

Read the pattern

SQL Anti-Join — Rows With No Match, 3 Spellings, 1 Trap

Customers who never ordered: LEFT JOIN…IS NULL, NOT EXISTS and NOT IN all return the same 6 — until one NULL makes NOT IN silently return zero.

Read the three spellings

SQL JOIN Nedir? INNER, LEFT ve Anti-Join — Türkçe

JOIN iki tabloyu ortak sütundan birleştirir. 40'a karşı 46 satır, kaybolan 6 müşteri, WHERE-ON tuzağı ve anti-join — gerçek veride, Türkçe.

Türkçe rehberi oku

SQL'de CTE (WITH) Nedir? Tek Sorguyla Anlatım

CTE, isim verilmiş alt sorgudur. Ne kazandırır, sütun-kapsamı tuzağı, virgülle çoklu CTE ve ne zaman gereksiz — Türkçe, çalıştırılabilir örneklerle.

Türkçe anlatımı oku

LEFT JOIN vs INNER JOIN — the Difference, Shown With Real NULL Rows

Same two tables, both joins, row counts shown: 40 vs 46, and exactly where the 6 extras come from. Plus the WHERE-vs-ON trap that silently converts one join into the other, and the anti-join trick. Ends with a 3-question self-check.

Read the comparison

What Is a CTE in SQL? Explained in One Query

A CTE is a subquery with a name — that's the entire concept. What the name buys you, the column-scoping rule that costs people real interview time, multiple CTEs as named pipelines, and when a plain subquery is honestly fine.

Read the explainer

Recursive CTE Explained — Org Charts, Trees, and When You Actually Need One

Anchor, step, stop. A real 50-person org chart walked in both directions (the direction is one ON clause), a number generator, the infinite-loop trap and its two defenses, and the honest list of cases where recursion is overkill.

Read the deep dive

SQL for AI Company Interviews — What OpenAI and Anthropic Actually Ask

The surprise is how little of it is about AI. Cohort retention, gap-based sessionization, usage percentiles and event dedup — the four product-analytics patterns these screens test, with runnable examples and the four mistakes that end interviews.

Read the AI-lab guide

Time-Series SQL for Hardware Interviews — the Ordering Trap

At NVIDIA and Tesla-style screens the table is ordered and the order carries the meaning. Frame clauses that change your answer silently, what ties do to RANK vs DENSE_RANK, LAG deltas, gaps and islands, and why HAVING is not WHERE.

Read the time-series guide

SQL JOINs Explained — Every Type, With Real Examples

INNER, LEFT, RIGHT, FULL, CROSS, SELF — every JOIN type with the WHERE-vs-ON LEFT JOIN bug as the centerpiece (the most expensive bug in production analytics SQL). Anti-join patterns, multi-table chains, five common mistakes that defeat most analysts.

Read the JOINs guide

SQL Window Functions Tutorial — RANK, LAG, Running Totals

ROW_NUMBER vs RANK vs DENSE_RANK with the side-by-side tie-handling table. PARTITION BY mental model, LAG/LEAD, ROWS BETWEEN frames, top-N per group as the most-asked interview pattern, plus five interview patterns to memorize.

Read the window functions guide

NULL Handling in SQL — The 5 Mistakes That Defeat Most Analysts

Why col = NULL never matches, the NOT IN trap with nullable subqueries, COUNT(*) vs COUNT(col), NULL contagion in arithmetic, and a NULL checklist for code review.

Read the NULL guide

SQL CTEs Explained — WITH Clause, Recursive CTEs, Subqueries

CTE vs subquery decision matrix, multi-CTE chains, recursive CTEs (anchor + recursive step + termination), org-chart and sequence-generation patterns, performance notes including the Postgres ≤11 fence, and three CTE anti-patterns.

Read the CTE guide

SQL GROUP BY Tutorial — Aggregation, HAVING, and the 5 Mistakes Most Analysts Make

The mental model for grouping, the one rule that prevents 80% of bugs, HAVING vs WHERE with execution order, conditional aggregation with CASE, ROLLUP/CUBE/GROUPING SETS, and the five mistakes that defeat most analysts.

Read the GROUP BY guide

SQL CASE WHEN Tutorial — Conditional Logic, Pivots, and the Common Bugs

Simple vs searched syntax, CASE in SELECT/ORDER BY/WHERE/GROUP BY, the conditional aggregation workhorse, CASE-based pivoting that works on every database, the NULL trap, and the 4 common bugs.

Read the CASE WHEN guide

SQL for Fraud Analytics — 5 Patterns Every Fraud Analyst Writes Weekly

Anomaly bounds (3-sigma, IQR), velocity rules with window functions, geographic mismatch with Haversine, cross-account self-join collusion detection, and recursive CTEs for chargeback investigation. Runnable examples on FDIC banking data.

Read the fraud analytics guide

The Complete FAANG SQL Interview Guide (2026)

Everything you need to ace the SQL interview at Meta, Google, Amazon, Apple, and Netflix. Topics by frequency, question patterns by company, and a 30-day study plan with concrete daily targets.

Read the FAANG guide

More tutorials coming. Want a specific topic covered? Email us.