I have a table with around 100 medicine interactions. I’m trying to make a statement where I insert X amount of drug names and it returns all rows where those drug names present in the first two columns.
If a patient has dicoumarol, warfarin and reserpine, it would return row 4 and 6 in the “Example of the table” picture below.
I use phpMyAdmin, which uses MySQL. I’ve tried a bunch of standard SELECT
queries with a WHERE
that says MedikamentA and MedikamentB equals the name of two drugs like:
SELECT * FROM MIdatabase
WHERE MedikamentA = 'dicoumarol'
AND MedikamentB = 'ergotamine' " OR " MedikmentA = 'ergotamine'
OR MedikamentB = 'dicoumarol'
Not completely correct, but I wrote it top of my head. Probably need to switch an OR
around and have some paranthesis.
I’m close to ripping a bit of hair off the top of my head trying to do this :p
3
Answers
I think your query doesn’t give you what you are expecting because it is missing parenthesis.
The easiest way to achieve what you want is to use
IN()
The above query is the same as the one below:
Try something like this:
You will need multiple LIKE statements along with the OR statement to meet the conditional requirements of calling for multiple drugs for each column. The second part of the LIKE statements needs AND as you will be referring to a separate column as part of the conditional statement.