tags:

views:

36

answers:

3

is this:

update batchinfo set instrument='Instrument 17' where
datapath like '%10497%' or 
datapath like '%10506%' or 
datapath like '%10516%' or 
datapath like '%11081%'
and instrument='Instrument 1'

the same as this:

update batchinfo set instrument='Instrument 17' where
datapath like '%10497%' and instrument='Instrument 1' or  
datapath like '%10506%' and instrument='Instrument 1' or  
datapath like '%10516%' and instrument='Instrument 1' or 
datapath like '%11081%' and instrument='Instrument 1'
+2  A: 

No - the AND only qualifies datapath like '%11081%'.

Don't take chances - use parentheses. They're cheaper.

Jonathan Leffler
+2  A: 

No, but these two are equivalent:

update batchinfo 
set instrument='Instrument 17' 
where 
    (datapath like '%10497%' or  
    datapath like '%10506%' or  
    datapath like '%10516%' or  
    datapath like '%11081%') 
    and instrument='Instrument 1' 

and

update batchinfo 
set instrument='Instrument 17' 
where 
    (datapath like '%10497%' and instrument='Instrument 1') or   
    (datapath like '%10506%' and instrument='Instrument 1') or   
    (datapath like '%10516%' and instrument='Instrument 1') or  
    (datapath like '%11081%' and instrument='Instrument 1') 
RedFilter
+2  A: 

No. See the mysql operator precedence chart. In general, if you are mixing AND and OR throwing in parenthesis is a good idea.

deinst
ok then i am screwed thank you have a nice day
I__
`AND` will have always have precedence over `OR`, not just in MySQL.
FrustratedWithFormsDesigner
@Frustrated Not necessarily. There are some strange operator precedence rules out there e.g. Smalltalk. I am a parenthesis fanatic for much that reason.
deinst
@deinst: Really? I thought those precedent rules came down from Boole himself!
FrustratedWithFormsDesigner
@Frustrated Just because there are precedence rules does not mean that language designers need to follow them. Smalltalk has the operators take precedence in the order they are written. Presumably this made sense back when a parenthesis cost a noticeable amount of storage.
deinst
@deinst: Good point.
FrustratedWithFormsDesigner