2012-07-06 270 views
-1

我將如何結合這些查詢? 「已刪除」字段是指示何時「刪除」主題的時間戳。該主題並未真正被刪除。如果它有實際的時間戳,我只是不會顯示它。關係數據庫查詢

$topics = "SELECT id FROM topics WHERE deleted = '0000-00-00 00:00:00'"; 

$comments = "SELECT * FROM comments WHERE topic_id IN($topics)"; 

回答

2

使用此解決方案:

SELECT a.* 
FROM comments a 
INNER JOIN topics b ON 
    a.topic_id = b.id AND 
    b.deleted = '0000-00-00 00:00:00'