我有问答(多选)表。答案表包含问题ID和答案ID(不是唯一ID)。
参考答案表:
QID AID Answer
_______________________________
1 1 Good
1 2 Very Good
1 3 Excellent
2 1 Delhi
2 2 Mumbai
2 3 Chennai
2 4 Kolkata
问题1(QID)的用户回答为2(AID),问题2(QID)为3(AID)。
我需要
SELECT the Answer "Very Good" (1 -> 2) and "Chennai" (2 -> 3).
(QID -> AID) => {(1 -> 2), (2 -> 3), .... n} sets
我没有主键。在这个表结构中如何实现我的选择?请帮助我...
答案 0 :(得分:0)
请尝试以下查询
// example array
$user_selected_array=array(
0=>array(1,2),
1=>array(2,3)
);
$WHERE='';
foreach($user_selected_array as $key=>$val) {
$WHERE .= ($WHERE!='')?" OR ":"";
$WHERE .= "(QID=$val[0] AND AID=$val[1])";
}
SELECT Answer FROM AnswerTable WHERE $WHERE