By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
create table `show` (
ID int,
Movie varchar(20),
IndexID int
);
insert into `show` values
(1, 'This', 1234),
(2, 'That', 1235);
create table Show_index (
IndexID int,
Genre_ID int
);
insert into Show_index values
(1234, 2),
(1234, 3),
(1235, 1),
(1235, 4);
create table Show_genres (
Genre_ID int,
Genre_Name varchar(20)
);
insert into Show_genres values
(1, 'One'),
(2, 'Two'),
(3, 'Three'),
(4, 'Four');
Records: 2 Duplicates: 0 Warnings: 0
Records: 4 Duplicates: 0 Warnings: 0
Records: 4 Duplicates: 0 Warnings: 0
select Movie as `show`, group_concat(Genre_Name) as Genres
from `show` s
inner join Show_index i on s.IndexID = i.IndexID
inner join Show_genres g on g.Genre_ID = i.Genre_ID
group by ID, Movie
order by ID
show | Genres |
---|---|
This | Two,Three |
That | One,Four |