1

我正在努力使以下 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]: Column already exists: 1060 Duplicate column name 'id'。

我确定这是一件小事,但我只是找不到我做错了什么,我真的很感激一些帮助。

感谢您的时间!

亚历克斯

4

1 回答 1

1

你不能用相同的别名FROM comments As Comment和命名两个表,例如GROUP BY Comment.uploads_id) Comment使用Comment_A和。Comment_B

于 2012-04-26T14:47:42.960 回答