w3resource

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. From the following table, write a SQL query to find those employees whose department numbers are included in 30 or 40 or 90. Return employee id, first name, job id, department id.

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)

Relational Algebra Expression:

Relational Algebra Expression: Display the employee Id, first name, job id, and department number for those employees whose department number equals 30, 40 or 90.

Relational Algebra Tree:

Relational Algebra Tree: Display the employee Id, first name, job id, and department number for those employees whose department number equals 30, 40 or 90.

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: From the following table, write a SQL query to find those employees who are working in the departments, which are not included in the department number 50 or 30 or 80. Return employee_id, first_name, job_id, department_id.
Next: From the following table, write a SQL query to find those employees who worked more than two jobs in the past. Return employee id.

Test your Programming skills with w3resource's quiz.

What is the difficulty level of this exercise?



SQL: Tips of the Day

MySQL export schema without data

mysqldump -h yourhostnameorIP -u root -p --no-data dbname > schema.sql

Ref: https://bit.ly/3xzB9dS