sql server 多表查询 一对多 无法得到正确的结果,请指教
SELECT Question.ID,title FROM Question inner JOIN Answer ON Question.id = Answer.qid order by id desc
其中主表Question(问题)的一条记录对应Answer(答案)表的多条记录,Question.id = Answer.qid,
无论是 inner JOIN 还是 left JOIN 得到的结果都不正确
SELECT Question.ID,title FROM Question 得到1009条结果
SELECT Question.ID,title FROM Question inner JOIN 得到1921条结果
SELECT Question.ID,title FROM Question left JOIN 得到2164条结果
我想把两个表连接而得到1009条结果,这个语句应该怎么写?
------解决方案--------------------
你是不是想看到有回复的问题的记录啊?如果是:
SELECT Question.* FROM Question inner JOIN Answer ON Question.id = Answer.qid order by id desc