我努力让以下MySQL声明发挥作用。
SELECT ItemGroup.users_id,ItemGroup.comments_id,ItemGroup.uploads_id,ItemGroup.posts_id,
Comment.id,Comment.uploads_id,
CommentUpload.id,
Upload.id,
Post.id
FROM items AS ItemGroup
LEFT JOIN (
SELECT Comment.id, Comment.uploads_id, CommentUpload.id, CommentUpload.uuid
FROM comments As Comment
INNER JOIN (
SELECT CommentUpload.id, CommentUpload.uuid
FROM uploads AS CommentUpload
) CommentUpload ON CommentUpload.id = Comment.uploads_id
GROUP BY Comment.uploads_id
) Comment ON Comment.id = ItemGroup.comments_id
LEFT JOIN (
SELECT Upload.id
FROM uploads AS Upload
) Upload ON Upload.id = ItemGroup.uploads_id
LEFT JOIN (
SELECT Post.id
FROM posts AS Post
) Post ON Post.id = ItemGroup.posts_id
WHERE ItemGroup.users_id = {$__cakeID__$}
AND (
Comment.id IS NOT NULL
OR Upload.id IS NOT NULL
OR Post.id IS NOT NULL
)
LIMIT 0 , 300
我试图找到与评论相关的上传但是它正在抛出SQLSTATE [42S21]:列已经存在:1060重复列名' id'。
我确定它有点小,但我无法找到我做错的事情,我真的很感激一些帮助。
感谢您的时间!
亚历
答案 0 :(得分:1)
您无法为具有相同别名FROM comments As Comment
和GROUP BY Comment.uploads_id) Comment
的两个表命名,例如使用Comment_A
和Comment_B
。