0

我正在使用以下查询:

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 中没有子项的问题)。任何人都有一个想法,我完全迷路了,希望那里有一个忍者:)

谢谢,

4

2 回答 2

2
select q.*
from tblQuestions q 
left outer join tblReplies r on q.queID = r.repQuestionID
where r.repQuestionID is null
于 2013-01-26T00:55:34.210 回答
1

使用NOT EXISTS

SELECT q.* 
FROM   tblquestions q
WHERE  NOT EXISTS (SELECT 1 
                   FROM   tblreplies r
                   WHERE  r.repquestionid = q.queid)
于 2013-01-26T00:54:49.627 回答