子查询的列太多;多个 select 个离子在一个 select 语句中

Subquery has too many columns; multiple selections in one select statement

免责声明:如果这是一个简单的问题或措辞不当的问题,我们深表歉意。我是菜鸟,我不知道如何表达这个问题,所以我不知道如何google。

我有两张桌子。 Math.question 和 Math.choice.

Math.question 包含问题文本列,以及 correctanswerid、wronganswerid1... 等等。

questiontext            correctanswerid     wronganswerID1    wronganswerid2
(question text          101                 102               103
  goes here)

Math.choice 包含选项的 ID 和选项文本。

id     choicetext
101    (text goes here)
102    (text goes here)
...

我想 select 来自 math.question 的问题文本和选择文本。所以它会显示如下内容:

questiontext     correctanswerText    wronganswer1text   wronganswer2text
(question text)  (choice text)        (choice text)      (choice text)

我试过这个:

select * from math.choice 
where id in (
    select CorrectAnswer_Choice_ID, Foil1_Choice_ID, Foil2_Choice_ID, Foil3_Choice_ID
    from math.question where id=301
);

我收到子查询有太多列的错误。我不太确定从这里到哪里去。

您需要多个 join。像这样:

select c.*, q1. choicetext, q2.choicetext, q3.choicetext
from math.choice c left join
     math.question q1
     on q1.id = c.CorrectAnswer_Choice_ID left join
     math.question q2
     on q2.id = c.Foil1_Choice_ID left join
     math.question q3
     on q3.id = c.Foil3_Choice_ID ;