我的SQL語句看起來像這樣想不通的MySQL聲明
SELECT q.content
FROM questions AS q, user_question_assoc AS uqa
WHERE uqa.user_id=? AND (q.course_id = uqa.course_id
OR q.lesson_id=uqa.lesson_id
OR q.question_id=uqa.question_id)
聲明的最後一部分是不是因爲我需要
WHERE uqa.user_id=? AND (q.course_id = uqa.course_id
OR q.lesson_id=uqa.lesson_id
OR q.question_id=uqa.question_id)
其實我想弄清楚1,僅在MySQL聲明從以下(我試過在人類的語言來解釋))
如果uqa.question_id
不爲0(或NULL)則
WHERE uqa.user_id=? AND (q.course_id = uqa.course_id
AND q.lesson_id=uqa.lesson_id
AND q.question_id=uqa.question_id)
如果uqa.lesson_id
不爲0(或NULL),但uqa.question_id
是0,那麼
WHERE uqa.user_id=? AND (q.course_id = uqa.course_id
AND q.lesson_id=uqa.lesson_id)
如果uqa.course_id
不爲0(或NULL),但uqa.question_id
和uqa.lesson_id
是0,那麼
WHERE uqa.user_id=? AND q.course_id = uqa.course_id
有什麼建議? THX提前