GROUP_CONCAT

-- Concatenar valores de cadena
-- GROUP_CONCAT

select first_name,last_name,group_concat(title) peliculas
from actor
join film_actor on actor.actor_id=film_actor.actor_id
join film on film.film_id=film_actor.film_id
group by actor.actor_id;

-- Puedo ordenar los valores
select first_name,last_name,group_concat(title ORDER BY title) peliculas
from actor
join film_actor on actor.actor_id=film_actor.actor_id
join film on film.film_id=film_actor.film_id
group by actor.actor_id;

-- Puedo cambiar el separador
select first_name,last_name,group_concat(title ORDER BY title SEPARATOR ' | ') peliculas
from actor
join film_actor on actor.actor_id=film_actor.actor_id
join film on film.film_id=film_actor.film_id
group by actor.actor_id;

Publicado por

Juan Pablo Fuentes

Formador de programación y bases de datos