Find Repeat Values in SQL: THE WAR ROOM
Some field agents keep ending up in incident reports. Management wants the repeat offenders identified before the next blown cover.
Mission briefing
THE WAR ROOM is chapter 12 and a duplicate-detection drill in disguise. The INCIDENTS table logs every security breach with an AGENT_ID; FIELD_AGENTS holds the roster. You join them, count incidents per agent with GROUP BY, and flag the agents whose count crosses a threshold with HAVING.
Finding values that appear more than N times is one of the most common SQL interview questions there is, usually phrased as finding duplicate records. Here it plays out as a counterintelligence review: one query, and the liabilities have nowhere to hide.
Three stages take you from the raw incident log to the final repeat-offender list.
A query pattern from this chapter
This is the shape of query you practice here, not the answer to any mission. The real stages come with their own data, objectives, and hints.
SELECT FIELD_AGENTS.CODENAME, COUNT(*) AS INCIDENT_TOTAL
FROM FIELD_AGENTS
INNER JOIN INCIDENTS ON FIELD_AGENTS.ID = INCIDENTS.AGENT_ID
GROUP BY FIELD_AGENTS.CODENAME
HAVING COUNT(*) >= 4;Related guides
Free guides that pair well with this chapter:
Play War Room now
Free in your browser, desktop only. Guest mode starts instantly with no signup; sign in with Google if you want progress saved across devices.