Founding Members

SQL practice problem 37 of 67 · Joins · Medium · 25 coins for your first accepted solve

A founding member joined a guild within 30 days of the day it was founded (30 days after still counts).

Return guild and player (names) for every founding membership, past or present. 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 Sizes · Next: The Runner-Up · All problems