MySQL问题 SQL优先级导致执行错误
问题现象
select * from x where a = 1 or b = 2 and c = 3
执行结果不符合预期。
问题分析
and优先级高于or,相当于select * from x where a = 1 or (b = 2 and c = 3)。
解决问题
改成select * from x where (a = 1 or b = 2) and c = 3。
问题现象
select * from x where a = 1 or b = 2 and c = 3
执行结果不符合预期。
问题分析
and优先级高于or,相当于select * from x where a = 1 or (b = 2 and c = 3)。
解决问题
改成select * from x where (a = 1 or b = 2) and c = 3。