Row fan-out after a JOIN

Row fan-out after a JOIN

You are a junior analyst at the PlayReel streaming service. The catalog lives in shows (one row per show) and seasons live in seasons: a show may have several. A teammate complained that after joining the two tables shows got duplicated and the catalog view looks bloated. You are asked to show the scale of the problem: for every show that occupies more than one row after the join, output how many rows it fans out into. Return columns: - title — show title; - join_rows — how many rows this show produces after joining to seasons (integer, strictly greater than 1). Sort by join_rows descending, then title ascending. Exclude shows that produce exactly one row or have no seasons at all.

Row order matters

PostgreSQLv16

Your query result will appear here

Focus radio
Paused · SomaFM · Fluid