w3resource
SQL exercises

SQL SORTING and FILTERING on HR Database: Display the first and last name, email, salary and manager ID of employees whose managers are hold the ID 120, 103 or 145

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

16. Write a query in SQL to display the first and last name, email, salary and manager ID, for those employees whose managers are hold the ID 120, 103 or 145.

Sample table : employees


Sample Solution:

SELECT first_name, last_name, email, 
  salary, manager_id
    FROM employees
     WHERE manager_id IN (120 , 103 , 145);

Sample Output:

 first_name  |  last_name  |  email   |  salary  | manager_id
-------------+-------------+----------+----------+------------
 Bruce       | Ernst       | BERNST   |  6000.00 |        103
 David       | Austin      | DAUSTIN  |  4800.00 |        103
 Valli       | Pataballa   | VPATABAL |  4800.00 |        103
 Diana       | Lorentz     | DLORENTZ |  4200.00 |        103
 Julia       | Nayer       | JNAYER   |  3200.00 |        120
 Irene       | Mikkilineni | IMIKKILI |  2700.00 |        120
 James       | Landry      | JLANDRY  |  2400.00 |        120
 Steven      | Markle      | SMARKLE  |  2200.00 |        120
 Peter       | Tucker      | PTUCKER  | 10000.00 |        145
 David       | Bernstein   | DBERNSTE |  9500.00 |        145
 Peter       | Hall        | PHALL    |  9000.00 |        145
 Christopher | Olsen       | COLSEN   |  8000.00 |        145
 Nanette     | Cambrault   | NCAMBRAU |  7500.00 |        145
 Oliver      | Tuvault     | OTUVAULT |  7000.00 |        145
 Winston     | Taylor      | WTAYLOR  |  3200.00 |        120
 Jean        | Fleaur      | JFLEAUR  |  3100.00 |        120
 Martha      | Sullivan    | MSULLIVA |  2500.00 |        120
 Girard      | Geoni       | GGEONI   |  2800.00 |        120
(18 rows)

Practice Online


HR database model

Query Visualization:

Duration:

Query visualization of Display the first and last name, email, salary and manager ID of employees whose managers are hold the ID 120, 103 or 145 - Duration

Rows:

Query visualization of Display the first and last name, email, salary and manager ID of employees whose managers are hold the ID 120, 103 or 145 - Rows

Cost:

Query visualization of Display the first and last name, email, salary and manager ID of employees whose managers are hold the ID 120, 103 or 145 - Cost

Contribute your code and comments through Disqus.

Previous: Write a query in SQL to display all the information from Employees table for those employees who was hired before June 21st, 2002.
Next: Write a query in SQL to display all the information for all employees who have the letters D, S, or N in their first name and also arrange the result in descending order by salary.

What is the difficulty level of this exercise?



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