I am trying to write a request that will allow me to search if the patient has NOT received the medicine. At first I thought I could just do something like this:
INNER JOIN prescript p ON p.id = patient.id AND p.med_id NOT IN (5128)
Where p.id and patient.id are the patient identifier, p.med_id refers to the medication identifier, and 5128 is the medication used in the request. The problem with this question is that if the patient had other medicines, they will appear. Therefore, if the patient has medicine 5128, but also another medicine that they will find. But I only want to return the patient if they do not have this medicine at all. The part that is complicated here is that I will not be able to find out the patient identifier in any of these cases. So I need a solution like this:
INNER JOIN prescript p ON p.id = patient.id AND (SELECT med_id FROM prescript WHERE id = p.pid) NOT IN (5128)
I thought it was possible if I could combine all med_id into one line, but my problem is that I use the query builder, so I am limited to adding joins and adding wheres only. Aka I can not use DECLARE .
source share