Oracle SQL 1Z0-071 [message #665015] |
Thu, 17 August 2017 13:44 ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
![](http://www.gravatar.com/avatar/a97594adb1d9e8a84c215a389f62a07b?s=64&d=mm&r=g) |
galileo213
Messages: 3 Registered: August 2017
|
Junior Member |
|
|
Hello Morris,
I just bought your eBook regarding Oracle sql 1z0-071 prep on Amazon. I have some concerns concerning logical operators precedence.
In *Limit the rows that are retrieved by a query* topic, you state OR operator has equal precedence with AND operator. But later inside the same topic you state according to the Oracle SQL Reference manual : AND condition has precedence over OR condition.
Could you please clarify for a better understanding ?
Thx
|
|
|
|
|
|
Re: Oracle SQL 1Z0-071 [message #665020 is a reply to message #665015] |
Thu, 17 August 2017 15:09 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
![](http://www.orafaq.com/forum/images/custom_avatars/102589.gif) |
Michel Cadot
Messages: 68675 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
SQL> select * from emp
2 where deptno = 10 and empno = 7782 or empno = 7902
3 /
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
7782 CLARK MANAGER 7839 09/06/1981 00:00:00 2450 10
7902 FORD ANALYST 7566 03/12/1981 00:00:00 3000 20
2 rows selected.
Is this
SQL> select * from emp
2 where deptno = 10 and (empno = 7782 or empno = 7902)
3 /
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
7782 CLARK MANAGER 7839 09/06/1981 00:00:00 2450 10
1 row selected.
or
SQL> select * from emp
2 where (deptno = 10 and empno = 7782) or empno = 7902
3 /
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
7782 CLARK MANAGER 7839 09/06/1981 00:00:00 2450 10
7902 FORD ANALYST 7566 03/12/1981 00:00:00 3000 20
2 rows selected.
But of course the correct answer is:
NEVER rely on any precedence, ALWAYS use parentheses to show what you want to do and be sure this is what you do.
[Updated on: Thu, 17 August 2017 15:11] Report message to a moderator
|
|
|
|