Reputation: 21
i have this query .. it always selecting all rows with between condition ignoring the type condition before
SELECT * FROM courses where course_type = 'ad' and (daily between 0 and 5000) OR (monthly between 0 and 5000)
it always return the all rows ignoring this
course_type = 'ad'
what am i missing? i know it will be something stupid and primitive/basic BUT i can't focus ADHD is killing me plus 2 days without sleep
thanks to everyone in advance
Upvotes: 2
Views: 27
Reputation: 1269883
You need to learn about how boolean expressions are parsed. Your expression requires additional parentheses:
where course_type = 'ad' and
( (daily between 0 and 5000) OR (monthly between 0 and 5000) )
Until you better understand boolean expressions, I would suggest that you always use explicit parentheses when you are mixing AND
s and OR
s.
Upvotes: 4