mysql - group SQL 2 tables -
i don't know if proper title question, not advanced sql user, know basics :)
create table movie (id int(4), title varchar(255)); create table genre (id int(4), mid int(4), genre varchar(200)); insert movie values (1, 'iron man'), (2, 'titanic'); insert genre values (1,1,'sci-fi'), (2,1,'action'), (3,2,'drama');
here have 2 tables, 1 movies , 1 genres.
i want create sql this.
id | title | genre 1 | iron man | action, sci-fi
in table genres mid
id of movie movie table
..
for movies genre
details :
select m.id id, m.title title, group_concat(g.genre) genre movie m left outer join genre g on (g.mid = m.id) group m.id
Comments
Post a Comment