select statement between ignoring condition

Viewed 23

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

1 Answers

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 ANDs and ORs.

Related