Mysql single query join 3 table and get all the results

前端 未结 3 1703
鱼传尺愫
鱼传尺愫 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 03:11

    This gets you the songs + artists for album 1.

    SELECT song_name, group_concat(artist_name) 
    FROM song 
    LEFT JOIN song_artist ON song.id=song_artist.song_id 
    LEFT JOIN artist ON song_artist.artist_id=artist.id 
    WHERE song.album_id=1
    

    Note that you did answer this question in another spot as well.

提交回复
热议问题