错误代码:1066。不是唯一的表/别名问题

时间:2017-05-04 12:41:38

标签: mysql sql

我正在尝试加入三个表:

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);

但我得到的不是唯一的错误,我应该在Album表中放置别名吗?

由于

2 个答案:

答案 0 :(得分:2)

Ablum子句中有AlbumFROM。我想你打算:

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;

修复是表名。另外,请注意表别名 - 它们使查询更容易编写和读取。另外,FROM子句中不需要括号。

答案 1 :(得分:1)


您可以使用以下查询,

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);