我有下面的查詢,它返回關聯的文章/文章數據和註釋。但是,如果沒有評論已發佈的任何內容都不會返回,因爲(我認爲)評論表中沒有加入關係。如果沒有評論,則不會使用帖子ID創建行。當沒有連接關係時SQL返回左表
任何人都可以解釋我將如何在一個查詢中獲取發佈數據和所有相關注釋嗎?
這裏的查詢: -
SELECT * FROM posts
LEFT OUTER JOIN comments
ON posts.ID = comments.comment_post_id
WHERE posts.ID = 8
AND posts.post_type = 'post'
AND posts.post_status = 'publish'
AND comments.comment_approved = 1
ORDER BY comments.comment_date_gmt DESC
非常感謝Alex! – KryptoniteDove 2013-03-13 13:43:16
有沒有更好的方法來做到這一點,以便我只從文章表中檢索文章數據一次? – KryptoniteDove 2013-03-13 13:47:07