正如标题所说我试图获得类似Facebook的功能,但出于某些原因,当我将其应用于左连接查询时,我得到重复的'post_id'列为什么? :/
我认为我解释得足够多,我希望最新的帖子首先显示在底部(从下到上,查看查询应该更多地解释你想要的内容)
这是工作查询(没有左连接但我需要左连接来加载每个帖子上的所有评论)
Working: (need the left join functions though)
$select_post_comments = $db->query("SELECT * FROM (
SELECT * FROM ".TABLE_PREFIX."groups_comments
WHERE post_id='$escape_post_id_row'
ORDER BY comment_id DESC LIMIT 7
) a ORDER BY comment_id");
获取重复的post_id错误:/
$select_post_comments = $db->query("SELECT * FROM (
SELECT * FROM spud_groups_posts
LEFT JOIN spud_groups_comments ON spud_groups_posts.post_id = spud_groups_comments.post_id
WHERE spud_groups_posts.post_id='$post_id_feed' ORDER BY comment_id DESC LIMIT 7
) a ORDER BY comment_id");
是什么导致我得到这个错误我已经尝试了所有知识
谢谢!
答案 0 :(得分:1)
post_id
是表spud_groups_posts
和spud_groups_comments
中的一列,您正在进行联接并选择导致重复列错误的所有列
选择具有表名前缀的列名,并且还只选择必需的列
SELECT spud_groups_posts.post_id as sgpostid, spud_groups_comments.comment_id
FROM spud_groups_posts
LEFT JOIN spud_groups_comments
ON spud_groups_posts.post_id = spud_groups_comments.post_id