﻿ SQL: Display the employees whose manager name is JONAS

# SQL Exercise: Display the employees whose manager name is JONAS

## SQL subqueries on employee Database: Exercise-30 with Solution

[An editor is available at the bottom of the page to write and execute the scripts.]

30. From the following table, write a SQL query to find those employees whose manager is JONAS. Return complete information about the employees.

Sample table: employees

Sample Solution:

``````SELECT *
FROM employees
WHERE manager_id IN
(SELECT emp_id
FROM employees
WHERE emp_name = 'JONAS');
``````

OR

``````SELECT *
FROM employees
WHERE manager_id =
(SELECT emp_id
FROM employees
WHERE emp_name = 'JONAS');
``````

Sample Output:

``` emp_id | emp_name | job_name | manager_id | hire_date  | salary  | commission | dep_id
--------+----------+----------+------------+------------+---------+------------+--------
67858 | SCARLET  | ANALYST  |      65646 | 1997-04-19 | 3100.00 |            |   2001
69062 | FRANK    | ANALYST  |      65646 | 1991-12-03 | 3100.00 |            |   2001
(2 rows)
```

Explanation:

The said query in SQL that retrieves information about employees who report to a manager named 'JONAS' from the 'employees' table.

This "emp_id" value is then used to filter the result of

An outer query includes rows where the "manager_id" column matches an "emp_id" value obtained from a subquery.

The subquery retrieves the "emp_id" of the employee with the name 'JONAS' from the 'employees' table.

## Practice Online

Structure of employee Database:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous SQL Exercise: Departments where maximum number of employees work.
Next SQL Exercise: List the employees not in the MARKETING department.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

﻿