Oracle OR

 如果想在emp table 內找job 為MANAGER 或 ANALYST的資料要怎麼做呢?

如果使用以下query:

SELECT *


FROM emp


WHERE job = 'MANAGER'


AND job = 'ANALYST'


會直接找不到結果


這時候就該使用or來完成


query:

SELECT *


FROM emp


WHERE job = 'MANAGER'


OR job = 'ANALYST'


EMPNOENAMEJOBMGRHIREDATESALCOMMDEPTNO
7698BLAKEMANAGER78391981/05/012850-30
7782CLARKMANAGER78391981/06/092450-10
7566JONESMANAGER78391981/04/022975-20
7788SCOTTANALYST75661982/12/093000-20
7902FORDANALYST75661981/12/033000-20


如果題目如下:
-- Get the names of those employees that are not managers nor salesmen and have a salary greater than or equal to 2000 

 query:
SELECT ENAME FROM EMP
WHERE JOB != 'MANAGER'
AND JOB != 'SALESMAN'
AND SAL >= 2000

這時候就應該要用and不能用or


0 Comments:

張貼留言