Double Agents

SQL practice problem 66 of 67 · Boss Fights · Hard · 50 coins for your first accepted solve

Some players joined a new guild before leaving their previous one. Two memberships of the same player overlap when one starts while the other is still active — joining on the very day the other ended does not count.

Return the name of every player with overlapping memberships. Row order does not matter.

Schema

CREATE TABLE players (
  id         INT PRIMARY KEY,
  name       TEXT NOT NULL,
  country    TEXT,            -- NULL = unknown
  level      INT NOT NULL,
  joined_on  DATE NOT NULL,
  mentor_id  INT              -- another player's id, or NULL
);

CREATE TABLE guilds (
  id          INT PRIMARY KEY,
  name        TEXT NOT NULL,
  founded_on  DATE NOT NULL
);

CREATE TABLE memberships (
  player_id  INT NOT NULL REFERENCES players(id),
  guild_id   INT NOT NULL REFERENCES guilds(id),
  joined_on  DATE NOT NULL,
  left_on    DATE             -- NULL = still a member
);

Write your query in the browser, run it on the sample data, then submit it against hidden test data.

Previous: Guild Power · Next: On Fire · All problems