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。

posted on 2024-04-04 14:01  王景迁  阅读(1)  评论(0编辑  收藏  举报

导航