SQL SELECT and WHERE Exercises
7 exercises with answers, easiest first.
Every query starts here. You name the columns you want, name the table and keep only the rows that matter. These exercises use one table at a time.
- 7 exercises, each from a real murder case
- 48% of players solve these on the first query
- Answers and hints are hidden until you click
The tables
| Table | Columns |
|---|---|
| suspect_info | id, case_id, name, role, relation, location, alibi_time |
| events | id, case_id, suspect_id, suspect_name, event_type, details, event_timestamp |
| suspect_reason | id, suspect_id, case_id, reason_type, summary, detail |
PostgreSQL. Times in alibi_time are stored as HH:MM:SS.
The exercises
1. Identify the Key Parties Involved
Use the suspect_info table to list the names and roles of all the key parties involved in this investigation.
filter by case_id = 3 in your query to focus only on the current investigation.
81% of players got this right on their first query (124 players, median 1 try).
Show the answer
SELECT name, role
FROM suspect_info
WHERE case_id = 3
2. Identify the Key Parties Involved
Use the suspect_info table to list the names and relations of all the key parties involved in this investigation.
filter by case_id = 5 in your query to focus only on the current investigation.
81% of players got this right on their first query (31 players, median 1 try).
Show the answer
SELECT name, relation
FROM suspect_info
WHERE case_id = 5
3. Who Had a Motive?
Samuel Ratchett (previously known as Cassetti) was a criminal. Use the suspect_info table to list every suspect's name and relation to find out who had a motive.
filter by case_id = 1 in your query to focus only on the current investigation.
66% of players got this right on their first query (360 players, median 1 try).
Show the answer
SELECT name, relation
FROM suspect_info
WHERE case_id = 1
4. Identify the Key Parties Involved
Use the suspect_info table to list the names and roles of all the key parties involved in this investigation.
filter by case_id = 2 in your query to focus only on the current investigation.
64% of players got this right on their first query (208 players, median 1 try).
Show the answer
SELECT name, role
FROM suspect_info
WHERE case_id = 2
5. When and where was everyone?
Each passenger gave an alibi, a time and place where they claimed to be during the night. Use the suspect_info table to list every suspect's name, alibi location and time to begin checking their stories.
filter by case_id = 1 in your query to focus only on the current investigation.
44% of players got this right on their first query (435 players, median 2 tries).
Show the answer
SELECT name, location, alibi_time
FROM suspect_info
WHERE case_id = 1
6. Identify the Passengers
Use the suspect_info table to list the names and roles of all the passengers on the train.
filter by case_id = 1 in your query to focus only on the current investigation.
30% of players got this right on their first query (505 players, median 2 tries).
Show the answer
SELECT name, role
FROM suspect_info
WHERE case_id = 1
7. Who last saw Roger Ackroyd alive?
Query the events table to identify the names of those who last saw Roger Ackroyd alive.
filter by case_id = 2 in your query to focus only on the current investigation.
19% of players got this right on their first query (164 players, median 3 tries).
Hint
- Look for event_type = 'seen alive' to find out who last saw Roger Ackroyd alive.
Show the answer
SELECT suspect_name
FROM events
WHERE case_id = 2
AND event_type = 'seen alive'