例如:
SELECT ename, job, deptno
FROM emp
WHERE deptno in (10, 20)
AND (ename like ‘%I‘ OR job like ‘%ER‘);
执行该sql,结果集如下:
1 JONES MANAGER 20
2 CLARK MANAGER 10
去掉上面sql查询条件中的括号,
SELECT ename, job, deptno
FROM emp
WHERE deptno in (10, 20)
AND ename like ‘%I‘ OR job like ‘%ER‘;
结果集如下:
1 JONES MANAGER 20
2 BLAKE MANAGER 30
3 CLARK MANAGER 10
出现如上差异的原因是:and比or优先级要高,括号可以改变条件判断的优先级!!!!!!!