w3resource

Oracle: List the name of all the employees who are not working in department number 20

Oracle Operator: Exercise-4 with Solution

Write a query to list the name of all the employees who are not working in department number 20.

Sample table: employees


Sample Solution :-

Oracle Code :

SELECT first_name, last_name, department_id 
FROM employees 
WHERE department_id !=20;

Output:


FIRST_NAME           LAST_NAME                 DEPARTMENT_ID
-------------------- ------------------------- -------------
Ellen                Abel                                 80
Sundar               Ande                                 80
Mozhe                Atkinson                             50
David                Austin                               60
Hermann              Baer                                 70
Shelli               Baida                                30
Amit                 Banda                                80
Elizabeth            Bates                                80
Sarah                Bell                                 50
David                Bernstein                            80
Laura                Bissot                               50

.........................

104 rows selected.

Oracle Code :

SELECT first_name, last_name, department_id 
FROM employees 
WHERE department_id  not in (20); 

Output:

FIRST_NAME           LAST_NAME                 DEPARTMENT_ID
-------------------- ------------------------- -------------
Ellen                Abel                                 80
Sundar               Ande                                 80
Mozhe                Atkinson                             50
David                Austin                               60
Hermann              Baer                                 70
Shelli               Baida                                30
Amit                 Banda                                80
Elizabeth            Bates                                80
Sarah                Bell                                 50
David                Bernstein                            80
Laura                Bissot                               50

.........................

104 rows selected.

Oracle Code :

SELECT first_name, last_name, department_id 
FROM employees 
WHERE department_id <>20;

Output:


FIRST_NAME           LAST_NAME                 DEPARTMENT_ID
-------------------- ------------------------- -------------
Ellen                Abel                                 80
Sundar               Ande                                 80
Mozhe                Atkinson                             50
David                Austin                               60
Hermann              Baer                                 70
Shelli               Baida                                30
Amit                 Banda                                80
Elizabeth            Bates                                80
Sarah                Bell                                 50
David                Bernstein                            80
Laura                Bissot                               50

................

104 rows selected.

Oracle Code :

SELECT first_name, last_name, department_id 
FROM employees 
WHERE department_id NOT LIKE  20;

Output:


FIRST_NAME           LAST_NAME                 DEPARTMENT_ID
-------------------- ------------------------- -------------
Steven               King                                 90
Neena                Kochhar                              90
Lex                  De Haan                              90
Alexander            Hunold                               60
Bruce                Ernst                                60
David                Austin                               60
Valli                Pataballa                            60
Diana                Lorentz                              60
Nancy                Greenberg                           100
Daniel               Faviet                              100
John                 Chen                                100

.................

104 rows selected.

Pictorial Presentation:

Pictorial: List the name of all the employees who are not working in department number 20

Improve this sample solution and post your code through Disqus.

Previous: Write a query to list the employees name and salary who’s daily salary is more than $100.
Next: Write a query to list the name of all the employees who are working as account manager and drawing a salary more than $5000.

What is the difficulty level of this exercise?



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/oracle-exercises/operator/oracle-operator-exercise-4.php