Tuesday 15 September 2015

mysql - SELECT title of movie and all actors of this -



mysql - SELECT title of movie and all actors of this -

i have database score movies , actors. , need select title of movies , actors. create next query:

select movies.title, concat_ws(' ', actors.name, actors.surname) actor movies left bring together movies_actors on movies.id = movies_actors.movie_id left bring together actors on actors.id = movies_actors.actor_id

and that:

+------------------------------+--------------+ | title | actor | +------------------------------+--------------+ | sin city: dame kill | eva greenish | | sin city: dame kill | bruce willis | +------------------------------+--------------+

but want this:

+------------------------------+--------------+ | title | actor | +------------------------------+--------------+ | sin city: dame kill | eva greenish | | | bruce willis | +------------------------------+--------------+

i seek utilize

select distinct movies.title...

but doesn't help.

can help me? thanks! database

create table movies ( id int not null primary key auto_increment, title varchar(255), director varchar(255), created date, budget decimal(12,2), box_office decimal(13,2), duration time ) create table actors ( id int not null primary key auto_increment, surname varchar(255), name varchar(255), birthday date ) alter table movies_actors add together foreign key (movie_id) references movies (id) alter table movies_actors add together foreign key foreign key (actor_id) references actors (id) insert 'movies' (`id`, `title`, `director`, `created`, `budget`, `box_office`, `duration`) values (1, 'sin city: dame kill for', 'frank miller, robert anthony rodriguez', '2014', 62000000.00, 38000000.00, '01:42:00') insert `actors` (`id`, `surname`, `name`, `birthday`) values (1, 'green', 'eva', '1980-07-06'), (2, 'willis', 'bruce', '1955-03-19')

how group_concat()

select movies.title, group_concat(concat(actors.name, ' ', actors.surname)) actors movies left bring together movies_actors on movies.id = movies_actors.movie_id left bring together actors on actors.id = movies_actors.actor_id grouping movies.title

mysql

No comments:

Post a Comment