Query Detective

Learn real-world SQL · SQL Server

Your query ran clean. The answer was wrong.

Query Detective finds the SQL traps that don't throw errors: NULLs, ties, duplicates and bad data that quietly change your numbers. Short fixes, full courses and realistic business data.

Case #01 · NOT INNo error
SELECT CustomerID
FROM   Customers
WHERE  CustomerID NOT IN (
       SELECT CustomerID FROM Orders
);
Expected2 rows
Returned0 rows

The clue: one NULL in Orders.CustomerID makes NOT IN match nothing. Use NOT EXISTS.

Free full courses

Learn SQL in one sitting, with chapters so you can jump to any lesson. Start with the fundamentals, then go deeper.

Series on the channel

Pick the format that fits your time.

10 SQL Traps

Ten queries that run without errors and still return the wrong answer, and how to catch each one.

Watch the traps

LumiBase: Database Detective

A story-driven investigation of an undocumented billing database, one clue at a time, all the way to the CFO.

Follow the case

2-Minute SQL Quick Wins

One technique per Short: TRY_CAST, TOP WITH TIES, ORDER BY NEWID(), NULLIF and more.

Watch the Shorts

Follow the investigation

New SQL tips every week. Same detective, wherever you scroll.

About

Created by Srini Voleti.

I'm a working data analyst who teaches SQL the way it's used on the job: with messy data, real business questions and results that have to be right. Examples use realistic synthetic datasets from everyday business: orders and customers, subscriptions and billing, and healthcare-style claims.

  • DatabaseSQL Server (T-SQL)
  • AudienceData analysts, report developers and anyone preparing for SQL interviews
  • DataSynthetic business and healthcare-style datasets. No real patient, customer or company data.