Reputation: 269
I'm trying to join 3 tables into 1. But I am getting a "Could not be bound" Error message.
As I'm new to SQL, I am not sure if its error in my code or if I have set the Table relationships up wrong?
I have a picture of my primary and foreign keys here: http://crystalise.tw/shadow/public.php?service=files&t=b036d2b2516576b27532b947dfb96293
Here is my SQL code I play with. I have managed to get the first attempt using only 2 tables to work fine. But I get problems when I try to implement the 3rd table. What should I take a closer look on this time ?
--
--SELECT Artists.nameArtist, Albums.nameAlbum
-- FROM Artists
-- INNER JOIN Albums
-- ON Artists.idArtist = Albums.idArtist
-- ORDER BY nameAlbum
--
SELECT Artists.nameArtist, Albums.nameAlbum, Songs.nameSong
FROM Artists
JOIN Songs
ON Artists.idArtist = Albums.idArtist
JOIN Albums
ON Artists.idArtist = Songs.idArtist
Upvotes: 0
Views: 193
Reputation: 1269493
You need to order your join conditions correctly. You cannot include a table name (or alias) in the on
condition before it appears in the from
clause:
SELECT Artists.nameArtist, Albums.nameAlbum, Songs.nameSong
FROM Artists
JOIN Songs
ON Artists.idArtist = Songs.idArtist
JOIN Albums
ON Artists.idArtist = Albums.idArtist
Upvotes: 2