1
I have two tables:
QUIZ
QUIZ_GERAL
I would need to list data from both tables when:
- The logged in user ID is equal to the IDCONTA field
OR
- When there is a row in the QUIZ table and there is no row in the table QUIZ_GERAL with the IDQUIZ and the IDLOGGED 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 idconta 1 does not list the quiz with id 1, because SELECT understands that it already exists, but it exists for the idconta 2.
How to list all quizes (1,2,3) for each user.
(I simplified the tables and selects well, they are more complex, but my doubt is in this stage that I spoke)
Thank you very much, that’s it! About * in SELECT, I left it here just so not to disturb, SELECT will be much bigger, but I left only the part that had doubts!
– caiocafardo
When I left the tests and went to practice, it was a mistake. If I add in QUIZ_GERAL a line to another user (idconta), NULL does not work if there is this line for one of the users...
– caiocafardo
I edited the question to better understand
– caiocafardo