说我下面有两个表,如何找到没有(0)答案的所有问题?
question
---------
id
content
和
answer
------
id
question_id
content
即question 1->* answers
- 编辑 -
要添加我的问题,我如何检索每个问题的答案数?
答案 0 :(得分:4)
select * from question q where not exists (select 1 from answer a where a.question_id=q.id)
回答编辑过的问题:
select q.id, content, count(a.id)
from question q
left outer join answer a
on q.id = a.question_id
group by q.id
答案 1 :(得分:0)
您可以使用以下查询找到。
Select * from question where id not in (Select question_id from answer)