mysql Column 'id' in field list is ambiguous

ERROR 1052 (23000): Column 'id' in field list is ambiguous
列'ID'在字段列表中重复,其实就是两张表有相同的字段,但是使用时表字段的名称前没有加表名,导致指代不明(连表情况下)
 
举例说明:
SELECT id FROM `aws_article` AS t1 JOIN (SELECT ROUND(RAND() * ((SELECT MAX(id) FROM `aws_article`)-(SELECT MIN(id) FROM `aws_article`))+(SELECT MIN(id) FROM `aws_article`)) AS id) AS t2 WHERE t1.id >= t2.id ORDER BY t1.id LIMIT 8
错误信息:
#1052 - Column 'id' in field list is ambiguous
正确语法:
SELECT t1.id FROM `aws_article` AS t1 JOIN (SELECT ROUND(RAND() * ((SELECT MAX(id) FROM `aws_article`)-(SELECT MIN(id) FROM `aws_article`))+(SELECT MIN(id) FROM `aws_article`)) AS id) AS t2 WHERE t1.id >= t2.id ORDER BY t1.id LIMIT 8

0 个评论

要回复文章请先登录注册