--
-- An alternative (better) way of showing multiple hosts with an episode. It
-- doesn't do much of a job with tags though.
--
-- (Actually doesn't work just now)

SELECT
    ep.id,
    ep.episode_key,
    ep.release_date,
    ep.title,
    (SELECT string_agg(host, ', ' ORDER BY host)
        FROM hosts h2,
             episodes_hosts_xref eh2
        WHERE eh2.hosts_id = h2.id
        GROUP BY eh2.episodes_id
        HAVING eh2.episodes_id = ep.id) AS hosts,
    string_agg(distinct 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.episode_key in ('hpr1777','hpr2297','hpr2400')
GROUP BY ep.id
ORDER BY ep.id;

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

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