Reputation: 675
I am running the following query
SELECT * FROM (`default_schemes`)
WHERE `region` = 'Location1'
OR `region` = 'Location2'
OR `region` = 'Location3'
OR `region` = 'Location4'
OR `region` = 'Location5'
OR `region` = 'Location6'
AND `finance` LIKE '%Equity%'
OR `guidance` LIKE '%Business Mentoring %'
Which will match the finance and guidance but pulls in all locations regarless of what is set, what am I missing?
Upvotes: 0
Views: 48
Reputation: 487
SELECT * FROM (`default_schemes`)
WHERE `region` IN ('Location1'
, 'Location2'
, 'Location3'
, 'Location4'
, 'Location5'
, 'Location6' )
AND (`finance` LIKE '%Equity%'
OR `guidance` LIKE '%Business Mentoring %')
Can you please check with this.
Upvotes: 0
Reputation: 111339
The and operator has higher precedence than the or operator, so something like A or B and C or D is parsed as A or (B and C) or D.
Add parentheses to the appropriate places to get the interpretation you want.
Upvotes: 0
Reputation: 33945
Perhaps you want this...
SELECT *
FROM default_schemes
WHERE region IN('Location1','Location2','Location3','Location4','Location5','Location6')
AND (finance LIKE '%Equity%' OR guidance LIKE '%Business Mentoring %');
Alternatively, you might want this...
SELECT *
FROM default_schemes
WHERE (region IN('Location1','Location2','Location3','Location4','Location5','Location6')
AND finance LIKE '%Equity%')
OR guidance LIKE '%Business Mentoring %';
Upvotes: 0
Reputation: 2896
SELECT * FROM `default_schemes`
WHERE `region` in ('Location1' ,'Location2' ,'Location3' , 'Location4' , 'Location5' ,'Location6' )
AND (`finance` LIKE '%Equity%'
OR `guidance` LIKE '%Business Mentoring%');
Upvotes: 2