I have created a relational database for songs, composers and lyricists.
My issue is that some songs can have multiple lyricists or multiple composers so when I search my database I would like a single song to be returned with an array of composers or lyricists if the particular song has had more than one contributor.
I am pulling data from several tables. Songs, composers [links composers to songs], composerdetails, lyricists [links lyricists to songs], lyricistdetails, Shows.
This is all brought together with the SQL query:
SELECT songs.songtitle, shows.showtitle, composerdetails.name composer, lyricistdetails.name lyricist
FROM songs
JOIN composers ON composers.songid = songs.songid
JOIN composerdetails ON composers.composerid = composerdetails.composerid
JOIN lyricists ON lyricists.songid = songs.songid
JOIN lyricistdetails ON lyricists.lyricistid = lyricistdetails.lyricistid
JOIN shows ON shows.showid = songs.showid
WHERE MATCH (
songtitle
)
AGAINST (
'$songname'
IN BOOLEAN
MODE
)
At the moment, I get
[0] => stdClass Object
(
[songtitle] => Maria
[showtitle] => West Side Story
[composer] => Leonard Bernstein
[lyricist] => Leonard Bernstein
)
[1] => stdClass Object
(
[songtitle] => Maria
[showtitle] => West Side Story
[composer] => Leonard Bernstein
[lyricist] => Stephen Sondheim
)
If I GROUP the songs by songtitle I would ignore the second lyricist. What is the best way to go about having the results returned as single rows, with an array for the lyricist if there is more than one?