字段列表中的列“大小”不明确

时间:2017-10-04 00:48:51

标签: mysql sql mysql-error-1052

无效的SQL:

SELECT
 info_hash,
 size,
 comment,
 created_by,
 announce_list,
 completed_by, 
 completed,
 seeders,
 leechers,
 ulspeed,
 dlspeed,
 dateline,
 thumbnail_dateline, 
 filename,
 filesize,
 visible,
 attachmentid,
 counter,
 postid, 
 IF(thumbnail_filesize > 0, 1, 0) AS hasthumbnail,
 thumbnail_filesize,
 attachmenttype.thumbnail AS build_thumbnail,
 attachmenttype.newwindow
FROM attachment
LEFT JOIN attachmenttype AS attachmenttype USING (extension)
WHERE postid IN (-1,2)
ORDER BY attachmentid;

MySQL错误:字段列表中的列'大小'不明确 错误号码:1052

2 个答案:

答案 0 :(得分:3)

这意味着size可能同时位于attachmentattachmenttype

如果您对列名进行限定,那么您将不会遇到此类问题。

答案 1 :(得分:1)

@GordonLinoff有正确的答案。但是如果你只是从某个地方复制了这段代码,那么你就很难理解他在说什么。 (也好好问问更好)。

以此为基础。请注意我如何将 A. 添加到size如果任何字段再次出现错误,您必须向其添加A.T.

SELECT info_hash, 
 A.size,
 comment,
 created_by,
 announce_list,
 completed_by, 
 completed, 
 seeders, 
 leechers, 
 ulspeed, 
 dlspeed,
 dateline, 
 thumbnail_dateline, 
 filename, 
 filesize, 
 visible,
 attachmentid, 
 counter,
 postid,
 IF(thumbnail_filesize > 0, 1, 0) AS hasthumbnail,
 thumbnail_filesize,
 T.thumbnail AS build_thumbnail, 
 T.newwindow
FROM attachment A
LEFT JOIN attachmenttype AS T USING (extension)
WHERE A.postid IN (-1,2)
ORDER BY A.attachmentid;