关系数据库查询

时间:2012-07-06 20:13:07

标签: mysql relational-database

我如何结合这些查询? “已删除”字段是指示主题何时被“删除”的时间戳。该主题并未真正被删除。如果它有实际的时间戳,我就不会显示它。

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

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

1 个答案:

答案 0 :(得分: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'