Reputation: 1555
I am trying to join three tables:
SELECT Songs.SongId,
Artist.ArtistFName,
Artist.ArtistLName,
Album.AlbumName,
Genre.GenreName,
Songs.SongTrackNr,
Songs.SongName,
Songs.SongDuration
FROM
(((Album
INNER JOIN Songs ON Album.AlbumId = Songs.AlbumId)
INNER JOIN Ablum ON Album.ArtistId = Artist.ArtistId)
INNER JOIN Album ON Album.GenreId = Genre.GenreId);
But I am getting the not unique error, where should i put aliases on the Album table?
Thanks
Upvotes: 0
Views: 2214
Reputation: 5141
You can use below query,
SELECT Songs.SongId,
Artist.ArtistFName,
Artist.ArtistLName,
Album.AlbumName,
Genre.GenreName,
Songs.SongTrackNr,
Songs.SongName,
Songs.SongDuration
FROM
Album Album
INNER JOIN Songs Songs
ON (Album.AlbumId = Songs.AlbumId)
INNER JOIN Artist Artist
ON (Album.ArtistId = Artist.ArtistId)
INNER JOIN Genre Genre
ON (Album.GenreId = Genre.GenreId);
Upvotes: 1
Reputation: 1269693
You have Ablum
and Album
in the FROM
clause. I think you intend:
SELECT s.SongId, ar.ArtistFName, ar.ArtistLName, a.AlbumName, g.GenreName,
s.SongTrackNr, s.SongName, s.SongDuration
FROM Album INNER JOIN
Songs s
ON a.AlbumId = s.AlbumId INNER JOIN
Artists ar
ON a.ArtistId = ar.ArtistId INNER JOIN
Genre g
ON a.GenreId = g.GenreId;
The fix is to the table names. In addition, notice the table aliases -- they make the query easier to write and to read. Plus the parentheses are not needed in the FROM
clause.
Upvotes: 2