The SQL Murder Mystery
- stellabonaparte
- May 20, 2022
- 3 min read

What a fun way to practice SQL!
Playing this SQL Mystery game was way more enjoyable than regular SQL practice.
Try it here https://mystery.knightlab.com/ before reading my results because--
Here Be Spoilers!
A crime has taken place, use the below ERD and your SQL knowledge to find the culprit. Here are the facts:
· It was a murder
· It occurred on Jan 15, 2018
· Location: SQL City

1) First , I queried for the given details:
SELECT *
FROM crime_scene_report
WHERE date = 20180115
AND type = 'murder'
AND city = 'SQL City'
Query Results:

2) The description from the last query gives two witnesses (one named) and the streets on which they live. From the ERD I saw the [person] table has addresses.
First I ordered just by address_number but that put one witness at the top and one at the bottom of a long list. To correct this I used ORDER BY street name so both were on top:
SELECT *
FROM person
WHERE address_street_name = 'Northwestern Dr'
OR address_street_name = 'Franklin Ave'
AND name LIKE 'Annabel%'
ORDER BY address_street_name, address_number DESC
LIMIT 2;
Query Results:
Perfect! I have my witnesses.

3) Now I can use their id numbers to locate their witness statements from [interview]:
SELECT *
FROM interview
WHERE person_id = 16371
OR person_id = 14887
Query Result:

4) The witnesses give me a lot of information!
Annabel Miller (id 16371) says she was an eyewitness to the murder and that she saw the culprit when she was working out on January 9th at her gym.
But first I will look at the data provided by witness Morty Schapiro (id 14887) starting with that partial membership id:
SELECT *
FROM get_fit_now_member
WHERE id LIKE '48Z%'
Query Results:

5) Next I see if any of these 3 suspects checked into the gym on January 9th:
SELECT *
FROM get_fit_now_check_in
WHERE membership_id LIKE '48Z%'
AND check_in_date = 20180109
This narrows it down to two of those suspects, Joe Germuska and Jeremy Bowers:

6) I want to see if Annabel was at the gym at the same time as either suspect. First, I used her person_id to get her gym membership_id:
SELECT *
FROM get_fit_now_member
WHERE person_id = 16371
That query returned her membership_id as 90081.

7) Next, I used her membership id to get her check-in times to compare to those of the suspects.
BOO, HISS!
This was a dead end, since she was there at the same time as both suspects that day!
What would Jessica Fletcher do?
Keep going!
8) Next, I looked at the license plate. Mr. Schapiro said the plate included “H42W” so I didn't assume it started with that sequence. I wrapped it in wildcards to allow for all possibilities.
I also only included males since the suspects are both male:
SELECT *
FROM drivers_license
WHERE plate_number LIKE '%H42W%'
AND gender = 'male'
Query Results:

9) Since that driver’s license id number is also in the [person] table, I searched for the two numbers:
SELECT *
FROM person
WHERE license_id IN (423327, 664760)
Query Results:

Only one of the above is one of my suspects, which means,
Jeremy Bowers is the murderer!

10) But wait! Looks like I have one more challenge to complete the game! And I have only two queries to complete it:
SELECT *
FROM interview
WHERE person_id = 67318

11) Ok, the table [drivers_license] has hair color and car make and model, the table [income] will show her income, and [facebook_event_checkin].
I think I can join all of these tables to the [person] table to find my villain, but I only have one query remaining to do it!:
SELECT p.ssn, p.name, i.annual_income, d.hair_color, d.height,
d.car_make, d.car_model, f.event_name, f.date
FROM person p
JOIN drivers_license d
ON p.license_id = d.id
JOIN income i
ON p.ssn = i.ssn
JOIN facebook_event_checkin f
ON p.id = f.person_id
WHERE 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 LIKE '201712%’
Query Results:


CONGRATS! You found the brains behind the murder! Everyone in SQL City hails you as the greatest SQL detective of all time!
I hope this walk-through was helpful to some of you who are practicing SQL. Keep it up a little every day!
- Stella
Credits
The SQL Murder Mystery was created by Joon Park and Cathy He while they were Knight Lab fellows. See the GitHub repository for more information.
Adapted and produced for the web by Joe Germuska.
This mystery was inspired by a crime in the neighboring Terminal City.
Web-based SQL is made possible by SQL.js
SQL query custom web components created and released to the public domain by Zi Chong Kao, creator of Select Star SQL.
Detective illustration courtesy of Vectors by Vecteezy
Original code for this project is released under the MIT License
Original text and other content for this project is released under Creative Commons CC BY-SA 4.0
Comments