SQL中AND与OR的优先级

突然发现,把基础给忘了,AND的优先级大于OR,试验如下:

Oracle

--Y
select 'Y' from dual where 1=2 and 1=2 or 1=1;

--Y
select 'Y' from dual where (1=2 and 1=2) or 1=1;

--No value
select 'Y' from dual where 1=2 and (1=2 or 1=1);

附,Oracle文档:

http://docs.oracle.com/cd/E17952_01/refman-5.1-en/operator-precedence.html

MySQL

复制代码
-- 1
select 1 from device_failure
where 1 = 2 and 1 = 2 or 1 = 1
limit 1;

-- 1
select 1 from device_failure
where (1 = 2 and 1 = 2) or 1 = 1
limit 1;

-- No value
select 1 from device_failure
where 1 = 2 and (1 = 2 or 1 = 1)
limit 1;
复制代码

 

posted @   nick_huang  阅读(34388)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示