Reputation: 47
I created the code below for a query that is supposed to return the records that satisfies two conditions:
1- ID is equal to #7
2- Disease is equal to one of the diseases written between the single quotes
The record with ID = 7 in the database I'm applying this query on doesn't have any of the diseases listed in the query as a value for the attribute "disease", so the query shouldn't return any record as a result. Yet it is returning the tuple with ID = 7 as a result for the query. Can you please tell me what is the problem with my code? I tried replacing the (||) with the word (OR) but I'm still getting the same result.
SELECT *
FROM patients
WHERE disease = ( 'migraine' || 'stroke' || 'concussion' || 'down_syndrome' || 'epilepsy' || 'autism' || 'hydrocephalus' || 'dyslexia' || 'dystonia' || 'aphasia' || 'coma' || 'aneurysm' || 'batten_disease' || 'brain_cancer' || 'alzheimers_disease' || 'amyolrophic_alteral_sclerosis' )
AND ID = '7'
Upvotes: 0
Views: 121
Reputation: 77876
You meant to use an IN
operator like
SELECT *
FROM patients
WHERE disease IN ( 'migraine', 'stroke' , 'concussion' , 'down_syndrome' , 'epilepsy' , 'autism' , 'hydrocephalus' , 'dyslexia' ,'dystonia' , 'aphasia' , 'coma' ,'aneurysm' , 'batten_disease' , 'brain_cancer' , 'alzheimers_disease' , 'amyolrophic_alteral_sclerosis' )
AND ID = '7';
Edit: per comment: ||
is a concatenation operator and not a OR
condition and so ultimately you getting a string concatanated with all diseases and that you are trying to compare.
Upvotes: 1