MySQL Forums
Forum List  »  PHP

Query divides movie titles into different columns
Posted by: Luigi Chiabrera
Date: November 13, 2019 11:58PM

Hello everyone
This query extracts me
'id', actor's id
'name', name of the actor
'image', image of the actor
'film', number of films in which there is the actor
'title' title of the film
from the database.

https://www.db-fiddle.com/f/aNZevWLBCLvFANXHH55FSh/0

It is possible to make sure that the films are not all
grouped in a single column but in two or more columns
distinct.

+----------+----------------------+------------------+------+--------------------------+
| actor_id | name | act_img | film | title |
+----------+----------------------+------------------+------+--------------------------+
| 3 | Max von Sydow | m_vsydow.jpg | 2 | Exorcist |
+----------+----------------------+------------------+------+--------------------------+
| 1 | Linda Blair | l_blair.jpg | 2 | Exorcist |
+----------+----------------------+------------------+------+--------------------------+
| 43 | Kitty Winn | k_winn.jpg | 2 | Exorcist |
+----------+----------------------+------------------+------+--------------------------+
| 7 | Eileen Dietz | e_dietz.jpg | 1 | Exorcist |
+----------+----------------------+------------------+------+--------------------------+
| 49 | Jack MacGowran | j_macgowran.jpg | 1 | Exorcist |
+----------+----------------------+------------------+------+--------------------------+
| 53 | Barton Heyman | b_heyman.jpg | 1 | Exorcist |
+----------+----------------------+------------------+------+--------------------------+
| 42 | Louise Fletcher | l_fletcher.jpg | 1 | Exorcist II: the Heretic |
+----------+----------------------+------------------+------+--------------------------+
| 47 | James Earl Jones | j_ejones.jpg | 1 | Exorcist II: the Heretic |
+----------+----------------------+------------------+------+--------------------------+
| 58 | Karen Knapp | no_foto.png | 1 | Exorcist II: the Heretic |
+----------+----------------------+------------------+------+--------------------------+
| 4 | Jason Miller | j_miller.jpg | 1 | Exorcist |
+----------+----------------------+------------------+------+--------------------------+
| 8 | Mercedes McCambridge | m_mcambridge.jpg | 1 | Exorcist |
+----------+----------------------+------------------+------+--------------------------+
| 50 | Thomas Bermingham | t_bermingham.jpg | 1 | Exorcist |
+----------+----------------------+------------------+------+--------------------------+
| 54 | Robert Sch√ľndler | r_sch√ľndler.jpg | 1 | Exorcist |
+----------+----------------------+------------------+------+--------------------------+
| 44 | Paul Henreid | p_henreid.jpg | 1 | Exorcist II: the Heretic |
+----------+----------------------+------------------+------+--------------------------+
| 48 | Belinda Beatty | b_beatty.jpg | 1 | Exorcist II: the Heretic |
+----------+----------------------+------------------+------+--------------------------+
| 5 | William O'Malley | w_omalley.jpg | 1 | Exorcist |
+----------+----------------------+------------------+------+--------------------------+
| 9 | Ron Faber | r_faber.jpg | 1 | Exorcist |
+----------+----------------------+------------------+------+--------------------------+
| 51 | Peter Masterson | p_masterson.jpg | 1 | Exorcist |
+----------+----------------------+------------------+------+--------------------------+
| 55 | Arthur Storch | a_storch.jpg | 1 | Exorcist |
+----------+----------------------+------------------+------+--------------------------+
| 45 | Dana Plato | d_plato.jpg | 1 | Exorcist II: the Heretic |
+----------+----------------------+------------------+------+--------------------------+
| 56 | Barbara Cason | b_cason.jpg | 1 | Exorcist II: the Heretic |
+----------+----------------------+------------------+------+--------------------------+
| 2 | Ellen Burstyn | e_burstyn.jpg | 1 | Exorcist |
+----------+----------------------+------------------+------+--------------------------+
| 6 | Lee J.Cob | l_jcob.jpg | 1 | Exorcist |
+----------+----------------------+------------------+------+--------------------------+
| 52 | Robert Symonds | r_symonds.jpg | 1 | Exorcist |
+----------+----------------------+------------------+------+--------------------------+
| 41 | Richard Burton | r_burton.jpg | 1 | Exorcist II: the Heretic |
+----------+----------------------+------------------+------+--------------------------+
| 46 | Ned Beatty | n_beatty.jpg | 1 | Exorcist II: the Heretic |
+----------+----------------------+------------------+------+--------------------------+
| 57 | Ken Renard | k_renard.jpg | 1 | Exorcist II: the Heretic |
+----------+----------------------+------------------+------+--------------------------+

For example actors id: 3, 1, 43 have two films in common
but it only displays one should be
Exorcist Exorcist II: the Heretic and if an actor is not on the list returns 'null',
film1 | film2
null Exorcist

Thanks in advance for your help

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.