如果想在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'
EMPNO | ENAME | JOB | MGR | HIREDATE | SAL | COMM | DEPTNO |
---|---|---|---|---|---|---|---|
7698 | BLAKE | MANAGER | 7839 | 1981/05/01 | 2850 | - | 30 |
7782 | CLARK | MANAGER | 7839 | 1981/06/09 | 2450 | - | 10 |
7566 | JONES | MANAGER | 7839 | 1981/04/02 | 2975 | - | 20 |
7788 | SCOTT | ANALYST | 7566 | 1982/12/09 | 3000 | - | 20 |
7902 | FORD | ANALYST | 7566 | 1981/12/03 | 3000 | - | 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:
張貼留言