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;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM