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;
原文地址:https://www.cnblogs.com/nick-huang/p/4027038.html