I'm having some issues trying to figure this out,
I can easily make it with a loop thus making a second query inside the first, but that doesn't seems to be efficient.
The objective is to obtain a array of rows that contain the song name and the various file types file names.
Here is simplified versions of the two tables:
Songs:
song_id*
song_title
Song_files:
file_id
file_song_id*
file_format
file_name
Wanted result:
[
{
"song_id": "1",
"song_title": "Musica Teste 1",
"song_mp3_filename": "song1.mp3",
"song_wav_filename": "song1.wav",
"song_flac_filename": "song1.flac"
},
{
"song_id": "2",
"song_title": "Musica Teste 2",
"song_mp3_filename": "song2.mp3",
"song_wav_filename": "song2.wav",
"song_flac_filename": "song2.flac"
},
{
"song_id": "3",
"song_title": "Musica Teste 3",
"song_mp3_filename": "song3.mp3",
"song_wav_filename": "song3.wav",
"song_flac_filename": "song3.flac"
}
]
Is there a more efficient way to do this without looping via php?
Thanks!
SELECT song_id, song_title, song_extra_title, song_duration, song_mp3_filename, song_wav_filename, song_flac_filename FROM songs s JOIN song_files f ON s.song_id = f.file_song_id;will join the two tables and return those fields.WHERE file_format = 'mp3', etc. I'm assuming), but where dosong_extra_titleandsong_durationcome from?