I have two tables:
QUIZ
QUIZ_GERAL
I would need to list data from both tables when:
- The logged in user ID is the same as the IDCONTA field
OU
- When there is a line in the QUIZ table and there is no line in the QUIZ_GERAL table with the user ID and ID of the logged in user
So far I've done something like this:
$sql1 = $pdo->prepare('SELECT * FROM quiz_geral
RIGHT JOIN quiz ON quiz_geral.idquiz = quiz.id
WHERE (quiz_geral.idconta = :idLogado) OR (quiz_geral.id IS NULL)
ORDER BY quiz.ano ASC, quiz.mes ASC');
The problem is that for the user with id 1 does not list the quiz with id 1, since SELECT understands that it already exists, strong> idconta 2.
How to list all quizes (1,2,3) for each user.
(I have simplified the tables and selects well, they are more complex, but my doubt is at this stage that I spoke)