SQL Detective Mystery is a crime case you crack by querying a database. A murder took place in SQL City on January 15, 2018, and all you remember is that a crime scene report exists. Every other clue lives in tables you can only open with SQL. SQL Detective Mystery is a great way to learn the language because each query you write is a real step in a story, not a dry exercise.
How the case unfolds
The page has several code boxes, each with a starter query. Edit one, press Run, and the results appear as a table underneath. The first boxes show how to list the tables and how to see the columns of one table, so you can map the database before you start digging.
From there you follow leads. Find the right report among more than a thousand. Read which witnesses it names. Look them up in the person table and read their interviews. Their statements mention a gym membership, a car and other details that you can match in still more tables.
When you have a name, run it through the Check your solution box. If it is right, a second, harder question opens up.
SQL Detective Mystery Controls
| Action | Keyboard | Mouse | Touch |
|---|---|---|---|
| Type or edit a query | Type in the code box | Click inside a code box | Tap a code box to bring up the keyboard |
| Run the query in a box | Shift + Enter | Click Run | Tap Run |
| Put the box back to its starting query | — | Click Reset | Tap Reset |
| Show the database diagram | — | Click the "click here" link above the last code box | Tap the "click here" link |
| Reveal a suggested query (walkthrough page) | — | Click Show Solution | Tap Show Solution |
Detective work as logic
A good query is a chain of conditions. “Reports where the date is this, the city is that and the type is murder” narrows a huge table to one row. That is set logic, the same AND and OR reasoning used in math and in search engines.
Joins teach you how data connects. The person table holds a license ID, the license table holds a plate number, and the gym table holds a membership ID. Linking them by those keys is how real databases answer questions that span many sources.
Tips for cracking the case
- Open the schema diagram first. It shows which columns link the tables.
- Filter by date, city and type together before reading any report.
- Use
LIKE '%text%'when a witness only gives part of a name or a plate. ORDER BY ... DESC LIMIT 1finds the last house on a street.- Join tables rather than copying IDs by hand.
- Keep notes. Names and numbers scroll away, and the page does not save your work.
Things Worth Knowing First
There is no timer, so take the case at whatever pace suits you. Typing on a phone works but is slow, so a keyboard helps. For another coding puzzle with clear goals, try Learn Git Branching or the event-driven code in Elevator Saga.
Tested and updated:













