Mysql single query join 3 table and get all the results

前端 未结 3 1681
鱼传尺愫
鱼传尺愫 2021-01-23 02:44

Hi i want to list all the song for the album and i want to list all the artist for individual song see below for example.

1. Song Title 1
   - Artist 1, Artist 2,         


        
3条回答
  •  走了就别回头了
    2021-01-23 02:58

    SELECT s.song_name, a.artist_name, al.album_name
    FROM artist a
    LEFT JOIN song_artist sa ON sa.artist_id = a.id
    LEFT JOIN song s ON s.id = sa.song_id
    LEFT JOIN album al ON al.id = s.album_id
    

    More info on JOIN

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题