I’m struggling to get the following MySQL statement to work.
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
I’m trying to find the uploads related to comments but it is throwing SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name ‘id’.
I’m sure it’s something small but I just can’t find what i’m doing wrong and I’d really appreciate some help.
Thank you for your time!
Alex
You cant name two tables with same alias
FROM comments As CommentandGROUP BY Comment.uploads_id) Comment, useComment_AandComment_Bfor example.