gpt4 book ai didi

sql - 为什么这个 SQL 代码给出错误 1066(不是唯一的表/别名 : 'user' )?

转载 作者:IT老高 更新时间:2023-10-28 23:58:59 27 4
gpt4 key购买 nike

这是我的表结构:

alt text

错误信息是:

#1066 - Not unique table/alias: 'user'

以下是我的代码。

SELECT article.* , section.title, category.title, user.name, user.name
FROM article
INNER JOIN section ON article.section_id = section.id
INNER JOIN category ON article.category_id = category.id
INNER JOIN user ON article.author_id = user.id
LEFT JOIN user ON article.modified_by = user.id
WHERE article.id = '1'

最佳答案

第二次加入用户表时需要给它起一个别名

例如

SELECT article . * , section.title, category.title, user.name, u2.name 
FROM article
INNER JOIN section ON article.section_id = section.id
INNER JOIN category ON article.category_id = category.id
INNER JOIN user ON article.author_id = user.id
LEFT JOIN user u2 ON article.modified_by = u2.id
WHERE article.id = '1'

关于sql - 为什么这个 SQL 代码给出错误 1066(不是唯一的表/别名 : 'user' )?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1435177/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com