我正在使用以下查询:
SELECT
count(tblReplies.repDate) as comReplies,
tblReplies.repDate
FROM tblReplies, tblQuestions, tblUsers
WHERE
tblQuestions.queID = tblReplies.repQuestionID
AND tblQuestions.queCompanyID = tblUsers.uCompanyID
AND tblUsers.uID = tblReplies.repUserID
AND tblUsers.uCompanyID = $comID
AND tblQuestions.queID = $queID
GROUP BY tblReplies.repID
ORDER BY tblReplies.repDate ASC
现在,我正在尝试修改查询以查找tblQuestions(queID)中没有回复的帖子(数据库中没有子项的问题tblReplies)。任何人都有一个想法,我完全迷失了,希望那里有一个忍者:)
谢谢,
答案 0 :(得分:2)
select q.*
from tblQuestions q
left outer join tblReplies r on q.queID = r.repQuestionID
where r.repQuestionID is null
答案 1 :(得分:1)
使用NOT EXISTS
:
SELECT q.*
FROM tblquestions q
WHERE NOT EXISTS (SELECT 1
FROM tblreplies r
WHERE r.repquestionid = q.queid)