My SQL statement looks like that
SELECT qe.id, qe.content, a.id, a.content, a.addDT, acr.checked, acr.score
FROM `questions_and_exercises` qe,
`questions from-to` qft
LEFT JOIN `questions-answers` qa ON (qa.qid=qe.id AND qa.uid=qft.uid)
LEFT JOIN answers a ON (a.id=qa.aid)
LEFT JOIN `answer_chk_results` acr ON (acr.aid=a.id)
AND qft.to_lid=2
WHERE qft.to_uid=3
Now, WHEREpart is not doing what I want. Trying to achieve this result:
- Select all where qft.to_lid=? (it means qft.to_uid=NULL) (ALWAYS)
- If there are rows where qft.to_uid=? (it means qft.to_lid=NULL) select them too (ONLY IF THERE ARE SUCH ROWS). In other words append to result.
Is there anyway to achieve this byu only one sql statement?
update

For ex when I query
WHERE qft.to_lid=2 AND qft.to_uid=NULL
WHERE qft.to_uid=2 AND qft.to_lid=NULL
I want to get rows with ids: 4,5,6 . If one of this where conditions has no result show other one. In other words this conditions has no relationship between each other
1 Answer