如何从多个表返回结果

时间:2014-04-06 18:33:36

标签: sql sqlite

我有两个表用于测验应用程序:

[Questions]
_id, question, correctAnswerId

[Answers]
_id, answer, questionId

当我查询问题时,例如

SELECT question FROM Questions WHERE _id = 2

我还希望获得与该问题相关的(正确和错误)答案。如何一次查询问题和答案,以便我不必单独查询答案?

1 个答案:

答案 0 :(得分:1)

使用JOIN

SELECT q.question, a.answer
FROM Questions q JOIN Answers a ON q._id = a.questionId
WHERE q._id = 2