SELECT `artists`.`id` as artist_id, `albums`.`id` as album_id, `songs`.`id` as song_id, `genres`.`id` as genre_id, `raw`.`location` as location, `raw`.`total_time` as length, `raw`.`bpm` as bpm FROM raw JOIN ( artists, albums, songs ) ON ( raw.album=albums.album AND raw.artist=artists.artist AND raw.song=songs.song AND raw.genre=genres.genre )