Practice · History · Hard

Who built the most (join + group)

For each pharaoh who built at least one monument, return the pharaoh name, their era, and how many monuments they built as monuments, most first (ties by name).

Runs in your browser. No signup needed.

What you are given

pharaohs JOIN monuments on pharaohs.name = monuments.builder, then GROUP BY the pharaoh. Combine a join with aggregation.

Starting point

SELECT p.name, p.era, COUNT(m.name) AS monuments
FROM pharaohs p
JOIN monuments m ON m.builder = p.name
GROUP BY p.name, p.era
ORDER BY monuments DESC, p.name;

The reference solution is checked automatically when you run your query on the practice page — results are compared row by row, and order matters for this one.

Did you know

Ramesses II was ancient Egypt’s greatest builder — the Ramesseum and Abu Simbel are only the most famous of his monuments. (Britannica)

More History challenges

Open it in the playground →