I have the following MySQL query:
SELECT tbPacientesComunicacao.id FROM tbPacientesComunicacao where tbPacientesComunicacao.idRefUser = 1 and tbPacientesComunicacao.idRefPaciente = 4 and tbPacientesComunicacao.id IN (select idRefComunicacao from tbPacientesComunicacaoDestinatarios where idRefUser IN (2,8));
The issue is that MySQL returns the ID if either 2 or 8 matches… how can I say hey only return the id if both numbers (2 and 8) matches?
Table tbPacientesComunicacao
id | description |
---|---|
1 | Something |
Table tbPacientesComunicacaoDestinatarios
idRefComunicacao | UserID |
---|---|
1 | 5 |
1 | 7 |
When a new record is being inserted, I have to check if that record doesn’t match any of the communications already in the database. So I pass the user IDs in an array(5,8) then I have to check it somehow if there is something in the database the matches EXACTLY this combination of UserIDs, in this test it shouldn’t match because I have 5 and 7 not 5 and 8 but using “in” it says it was matched because it found at least one of them… how can I determine that only matches if all numbers in the array matches the table userID?
Cezar Duarte is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.