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 @ 2014-10-15 18:53  nick_huang  阅读(34379)  评论(0编辑  收藏  举报