SELECT s.id, s.show_start, s.show_end, s.bekeken, s.website, s.afbeelding,
(SELECT titel FROM serie_details WHERE taalcode = 'oo' AND serie_id = s.id) AS titel,
(SELECT beschrijving FROM serie_details WHERE taalcode = 'oo' AND serie_id = s.id) AS beschrijving,
ARRAY_AGG(d.titel) AS alt_titels,
(SELECT ARRAY_AGG(num[1]) FROM afleveringen WHERE serie_id = s.id) AS afleveringen,
(SELECT COUNT(id) FROM afleveringen WHERE serie_id = s.id) AS totaal
FROM series AS s
LEFT JOIN serie_details AS d ON d.serie_id = s.id
WHERE s.id = 6
GROUP BY s.id, s.show_start, s.show_end, s.bekeken, s.website, s.afbeelding
series
is the table with the series, serie_details
contains alternative names for series and afleveringen
contains episode numbers and titles for those episodes.
I've tried using multiple JOINs but then I get duplicated results, because there are multiple rows in the serie_details
table. The query was:
SELECT s.id, s.show_start, s.show_end, s.bekeken, s.website, s.afbeelding, COUNT(a.id) AS totaal,
(select titel from serie_details where taalcode = 'oo' and serie_id = s.id) AS titel,
(select beschrijving from serie_details where taalcode = 'oo' and serie_id = s.id) AS beschrijving,
ARRAY_AGG(a.num[1]) AS afleveringen,
ARRAY_AGG(d.titel) AS alt_titels
FROM series AS s
LEFT JOIN afleveringen AS a ON a.serie_id = s.id
LEFT JOIN serie_details AS d ON d.serie_id = s.id
WHERE s.id = 6
GROUP BY s.id, s.show_start, s.show_end, s.bekeken, s.website, s.afbeelding