w3resource
SQL exercises

SQL SORTING and FILTERING on HR Database: Display the employee Id, first name, job id, and department number for those employees whose department number equals 30, 40 or 90

SQL SORTING and FILTERING on HR Database: Exercise-21 with Solution

21. Write a query in SQL to display the employee Id, first name, job id, and department number for those employees whose department number equals 30, 40 or 90.

Sample table : employees


Sample Solution:

SELECT employee_id, first_name, job_id, department_id
 FROM employees
  WHERE department_id IN (30 , 40 , 90);

Sample Output:

 employee_id | first_name |  job_id  | department_id
-------------+------------+----------+---------------
         100 | Steven     | AD_PRES  |            90
         101 | Neena      | AD_VP    |            90
         102 | Lex        | AD_VP    |            90
         114 | Den        | PU_MAN   |            30
         115 | Alexander  | PU_CLERK |            30
         116 | Shelli     | PU_CLERK |            30
         117 | Sigal      | PU_CLERK |            30
         118 | Guy        | PU_CLERK |            30
         119 | Karen      | PU_CLERK |            30
         203 | Susan      | HR_REP   |            40
(10 rows)

Practice Online


HR database model

Query Visualization:

Duration:

Query visualization of Display the employee Id, first name, job id, and department number for those employees whose department number equals 30, 40 or 90 - Duration

Rows:

Query visualization of Display the employee Id, first name, job id, and department number for those employees whose department number equals 30, 40 or 90 - Rows

Cost:

Query visualization of Display the employee Id, first name, job id, and department number for those employees whose department number equals 30, 40 or 90 - Cost

Contribute your code and comments through Disqus.

Previous: Write a query in SQL to display the employee ID, first name, job id, and department number for those employees who is working except the departments 50,30 and 80.
Next: Write a query in SQL to display the ID for those employees who did two or more jobs in the past.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming