SQL Murder Mystery Walkthrough
Every step of the Knight Lab mystery. A hint first, the query second, the answer last.
The SQL Murder Mystery gives you a database and almost no instructions. That is the fun of it and also where people get stuck. This walkthrough gives you a nudge at each step, so you only see as much as you need.
Spoilers are hidden. Each step shows a hint. The query and what it finds stay closed until you click them. The killer's name is only inside the last boxes.
What the SQL Murder Mystery is
- Made by: Joon Park and Cathy He at Northwestern University's Knight Lab. Play it at mystery.knightlab.com
- The setup: a murder happened in SQL City on January 15, 2018. You lost the crime scene report and have to find the killer in the police database
- The database: SQLite, 9 tables, runs in your browser
- How long it takes: 30 to 60 minutes if you know a little SQL
- We didn't make it. We make Query the Murder, which has 18 cases in the same spirit. This page is a guide from fans
The tables you'll use
| Table | What it holds | Columns that matter |
|---|---|---|
| crime_scene_report | One row per crime | date, type, description, city |
| person | Everyone in the city | id, name, license_id, address_number, address_street_name, ssn |
| interview | What witnesses and suspects said | person_id, transcript |
| get_fit_now_member | Gym members | id, person_id, name, membership_status |
| get_fit_now_check_in | Gym visits | membership_id, check_in_date |
| drivers_license | Looks and cars | id, height, hair_color, gender, plate_number, car_make, car_model |
| facebook_event_checkin | Who went to which event | person_id, event_name, date |
| income | Salaries | ssn, annual_income |
| solution | Where you check your answer | user, value |
Dates are stored as whole numbers. January 15, 2018 is 20180115, with no quotes and no dashes. This trips up more people than anything else in the game.
Step 1: Find the crime scene report
Goal: read the report for the murder in SQL City on January 15, 2018.
Hint: filter crime_scene_report on three columns: the date, the type and the city.
Show the query
SELECT *
FROM crime_scene_report
WHERE date = 20180115
AND type = 'murder'
AND city = 'SQL City';
Show what it finds
There were two witnesses. The first lives at the last house on Northwestern Dr. The second is named Annabel and lives somewhere on Franklin Ave.
Step 2: Find the two witnesses
Goal: turn those two descriptions into two rows of the person table.
Hint: "the last house" is the highest address_number on the street. For the second witness you only know a first name, so you need LIKE.
Show the queries
-- Witness 1: last house on Northwestern Dr
SELECT *
FROM person
WHERE address_street_name = 'Northwestern Dr'
ORDER BY address_number DESC
LIMIT 1;
-- Witness 2: Annabel on Franklin Ave
SELECT *
FROM person
WHERE address_street_name = 'Franklin Ave'
AND name LIKE 'Annabel%';
Show what they find
Morty Schapiro (id 14887) and Annabel Miller (id 16371).
Step 3: Read their interviews
Goal: find out what each witness told the police.
Hint: the interview table links to people by person_id. You can look up both ids at once with IN or JOIN interview to person.
Show the query
SELECT p.name, i.transcript
FROM interview AS i
JOIN person AS p ON p.id = i.person_id
WHERE i.person_id IN (14887, 16371);
Show what it finds
- Morty heard a gunshot and saw a man run out carrying a Get Fit Now Gym bag. The membership number on the bag started with 48Z and only gold members get those bags. The man drove off in a car whose plate included H42W
- Annabel saw the murder and recognised the killer from her gym, where she saw him on January 9
Step 4: Check the gym
Goal: find gold members whose membership id starts with 48Z and who checked in on January 9.
Hint: you need two tables. get_fit_now_member has the id and status. get_fit_now_check_in has the dates. Join them on the membership id.
Show the query
SELECT m.id, m.person_id, m.name
FROM get_fit_now_member AS m
JOIN get_fit_now_check_in AS c ON c.membership_id = m.id
WHERE m.id LIKE '48Z%'
AND m.membership_status = 'gold'
AND c.check_in_date = 20180109;
Show what it finds
Two suspects: Joe Germuska and Jeremy Bowers.
Step 5: Match the licence plate
Goal: see which of the two suspects drives a car with H42W in its plate.
Hint: plates are in drivers_license and person.license_id points to it. Use LIKE '%H42W%' because the letters are in the middle of the plate.
Show the query
SELECT p.id, p.name, d.plate_number
FROM person AS p
JOIN drivers_license AS d ON d.id = p.license_id
WHERE d.plate_number LIKE '%H42W%';
Show who the murderer is
Three people have a matching plate and only one of them is also on the gym list: Jeremy Bowers. Check it by running INSERT INTO solution VALUES (1, 'Jeremy Bowers'); and then SELECT value FROM solution;
Step 6: Find out who hired him
The game tells you there is more to the story. This is the part most people miss.
Goal: read the murderer's own interview.
Hint: the same interview table, this time with the killer's person_id.
Show the query
SELECT i.transcript
FROM interview AS i
JOIN person AS p ON p.id = i.person_id
WHERE p.name = 'Jeremy Bowers';
Show what it finds
He was hired by a rich woman. She is between 65 and 67 inches tall, has red hair and drives a Tesla Model S. She went to the SQL Symphony Concert three times in December 2017.
Step 7: Catch the mastermind
Goal: find the one woman who fits every clue.
Hint: this is the hardest query in the game. Join person to drivers_license for her looks and car, then to facebook_event_checkin for the concerts. Use GROUP BY and HAVING COUNT(*) = 3 to count her visits.
Show the query
SELECT p.name
FROM person AS p
JOIN drivers_license AS d ON d.id = p.license_id
JOIN facebook_event_checkin AS f ON f.person_id = p.id
WHERE d.gender = 'female'
AND d.hair_color = 'red'
AND d.height BETWEEN 65 AND 67
AND d.car_make = 'Tesla'
AND d.car_model = 'Model S'
AND f.event_name = 'SQL Symphony Concert'
AND f.date BETWEEN 20171201 AND 20171231
GROUP BY p.name
HAVING COUNT(*) = 3;
Show who the mastermind is
Miranda Priestly. Insert her name into the solution table the same way to see the final message.
The SQL you just used
| Step | SQL | Practise it again |
|---|---|---|
| 1 | WHERE with AND | Case 1: Murder on the Orient Express |
| 2 | ORDER BY, LIMIT, LIKE | Case 2: The Murder of Roger Ackroyd |
| 3 to 5 | JOIN and IN | Case 4: Murder in Mesopotamia |
| 7 | Several JOINs, GROUP BY and HAVING | Case 6: Crooked House |
Where people get stuck
My first query returns nothing
Check the date. It is the number 20180115, not the text '2018-01-15'. Then check the city: 'SQL City' with capital letters.
How do I find "the last house" on a street?
Sort by address_number from highest to lowest and keep one row: ORDER BY address_number DESC LIMIT 1.
I found two people at the gym. Which one is it?
Use the second clue. Only one of them has a car with H42W in the plate.
The game says I found the murderer. Am I done?
Not quite. Read the message again. It asks you to find who was behind the murder, which is steps 6 and 7 above.
Can I solve it in one query?
Yes. Join get_fit_now_member, get_fit_now_check_in, person and drivers_license, then filter on the gym id, the date and the plate. It is a good exercise once you know the answer.
Finished it? There are 18 more
The SQL Murder Mystery is one case. If you want that feeling again, Query the Murder has 18 cases based on Agatha Christie novels.
| SQL Murder Mystery | Query the Murder | |
|---|---|---|
| Cases | 1 | 18 |
| Story | A murder in SQL City | Orient Express, Death on the Nile, And Then There Were None and 15 more |
| Guidance | One open puzzle | 5 questions per case, with hints |
| Difficulty | One level | Easy, medium and hard, up to window functions |
| Database | SQLite | PostgreSQL |
| Price | Free | Free, no account |
Keep going: About the game | SQL JOINs explained | WHERE vs HAVING
SQL Murder Mystery was created by Knight Lab at Northwestern University. Query the Murder is not affiliated with Knight Lab.