我有一个查询问题,如下所示,问题是当它在结果中显示时只显示有答案的问题。我需要一个问题来表明它是否有答案。如果没有v.answer,则需要a.question在结果中显示,并以null作为答案。
SELECT
a.Question, v.Answer
FROM
Question a AS a
FULL OUTER JOIN
Answer v AS v ON a.ID = v.ID
AND a.surveyID = v.surveyID
答案 0 :(得分:0)
您需要一个LEFT JOIN
SELECT Q.Question,
A.Answer
FROM Questions Q LEFT JOIN Answers A ON Q.ID = A.ID
AND Q.surveyID = A.surveyID;
这将返回所有有答案的问题,如果没有答案,则将返回NULL
。