2014-11-03 103 views
0

正如標題說我想獲得一個像功能的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"); 

是什麼原因造成我牛逼o得到這個錯誤我已經嘗試了一切以我的知識

謝謝!

回答

1

post_id是在這兩個表spud_groups_postsspud_groups_comments和你正在做一個JOIN和選擇所有列導致重複的列錯誤

選擇列名和表名的前綴,並只選擇需要的列

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 
+0

謝謝;)應該有幫助:D – 2014-11-03 04:06:42

+0

@Jan Dooly,如果有幫助,你可以接受答案 – radar 2014-11-03 12:44:08

+0

完成:)再次感謝 – 2014-11-03 13:10:07