MySQL子查询错误:SQLSTATE [42S21]:列已存在:1060重复列名'id'

时间:2012-04-26 14:42:07

标签: mysql

我努力让以下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'。

我确定它有点小,但我无法找到我做错的事情,我真的很感激一些帮助。

感谢您的时间!

亚历

1 个答案:

答案 0 :(得分:1)

您无法为具有相同别名FROM comments As CommentGROUP BY Comment.uploads_id) Comment的两个表命名,例如使用Comment_AComment_B