如何在问题表中找到未回答的问题?

时间:2012-08-16 08:05:41

标签: php mysql sql mysql5

我有两张桌子

question
------------------------------
qid  |  qname  |  description
------------------------------
1      ssc?       blabla

2      BIE        blabla

3      msc        blabla

answer
----------------------------
aid  | uid  | qid | answered_on
-------------------------------
1      1      1     ssc means

2      2      1     ssc
-------------------------------

现在我想获得如何编写查询的未解答的问题?你能告诉任何人。

i get the result like 

qid | qname
-----------
2     BIE
3     msc

2 个答案:

答案 0 :(得分:1)

SELECT qid, qname FROM question 
WHERE qid NOT IN (SELECT DISTINCT qid FROM answer)

虽然不是真正的服务器故障问题。

答案 1 :(得分:1)

select * from  users as ru left join answers as ra on ru.uid=ra.uid 
left join questions as rq on rq.uid=ru.uid 
where   rq.qid not in(select qid from answers) group by rq.qid order by rq.qid desc

如果您有用户表

,这可能很有用