Advertisement
elena1234

common table expression and GROUP_CONCAT in MySQL

Feb 21st, 2023 (edited)
1,171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.39 KB | None | 0 0
  1.   WITH CTE (first_name, last_name, title)
  2.    AS
  3.    (
  4.         SELECT actor.first_name,
  5.         actor.last_name,
  6.         film.title
  7.         FROM actor
  8.         JOIN film_actor
  9.         ON actor.actor_id = film_actor.actor_id
  10.         JOIN film
  11.         ON film_actor.film_id = film.film_id
  12.     )  
  13.        
  14.     SELECT CTE.first_name, CTE.last_name, GROUP_CONCAT(CTE.title) as titles
  15.     FROM CTE
  16.     GROUP BY CTE.first_name, CTE.last_name;
  17.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement