I have 3 tables:
- questions
- answers
- qa_assoc which standing for
question id<->answer idrelationship
What I’m trying to do is following: Select all questions, if any question has answer select answer too.
SELECT q.id, q.content, a.id, a.content, a.dt
FROM questions q
JOIN qa_assoc qaa ON qaa.qid=q.id
JOIN answers a ON a.id=qaa.aid
WHERE q.course_id=? AND q.lesson_id=? AND a.user_id=?
But this sql only selects the questions which have an answer. How can I achieve my idea? any suggestions? thx in advance
You can’t have a in your
WHEREif you want rows without a, moved it to theONpart