--
-- An attempt to produce a query that summarises multiple hosts and multiple
-- tags for an episode. Not very successful, but kept for reference.
--
SELECT
    ep.id,
    ep.release_date,
    ep.title,
    string_agg(distinct h.host, ', ') AS hosts,
    string_agg(t.tag, ', ') AS taglist
FROM episodes ep
JOIN episodes_hosts_xref eh ON (eh.episodes_id = ep.id)
JOIN hosts h ON (h.id = eh.hosts_id)
LEFT JOIN episodes_tags_xref et ON (et.episodes_id = ep.id)
LEFT JOIN tags t ON (t.id = et.tags_id)
WHERE ep.id BETWEEN 2200 AND 2400
GROUP BY ep.id, h.host
ORDER BY ep.id;

-- Footer ---------------------------------------------------------------------

-- vim: syntax=pgsql:ts=8:sw=4:ai:tw=78:et:fo=tcrqn21
