I have a table of patient ID and the medication they use. If patient fails drug A they will use B, while further drug resistance leads to drug C, and so on.
I want to find out patients who use certain drug(i.e. 'B') and stopped there without trying new drug on the list. My code is dumb and not efficient if the Medication list is short.
PatientID MedicationName
13 A
13 B
13 C
32 A
32 A+
32 B
32 C
38 A
38 C
38 D
42 B
42 F
42 G
53 E
53 F
select *
from PatientMaster
where MedicationName = 'B'
and PatientID not in (
select PatientID
from PatientMaster
where MedicationName in ( 'C', 'D', 'E', 'F', 'G' ))
If my MedicationName list contains >1000 names, how do I have a kinda "cut-off" for categorical value and select patients who stopped at certain drugs?