w3resource

SQL Subquery Exercises: Display the employee name, employee id and salary of all employees who report to Payam

SQL SUBQUERY: Exercise-5 with Solution

From the following table, write a SQL query to find those employees who report to that manager whose first name is ‘Payam’. Return first name, last name, employee ID and salary.

Sample table: employees


Sample Solution:

SELECT first_name, last_name, employee_id, salary  
FROM employees  
WHERE manager_id = 
(SELECT employee_id  
FROM employees  
WHERE first_name = 'Payam' 
);

Sample Output:

first_name	last_name	employee_id	salary
Jason		Mallin		133		3300.00
Michael		Rogers		134		2900.00
Ki		Gee		135		2400.00
Hazel		Philtanker	136		2200.00
Kelly		Chung		188		3800.00
Jennifer	Dilly		189		3600.00
Timothy		Gates		190		2900.00
Randall		Perkins		191		2500.00

Pictorial Presentation:

SQL Subqueries: Display the employee name, employee id and salary of all employees who report to Payam

Practice Online


Query Visualization:

Duration:

Query visualization of Display the employee name, employee id and salary of all employees who report to Payam - Duration

Rows:

Query visualization of Display the employee name, employee id and salary of all employees who report to Payam - Rows

Cost:

Query visualization of Display the employee name, employee id and salary of all employees who report to Payam - Cost

Contribute your code and comments through Disqus.

Previous: From the following table, write a SQL query to find those employees who earn more than the average salary. Return employee ID, first name, last name.
Next: From the following tables, write a SQL query to find all those employees who work in the Finance department. Return department ID, name (first), job ID and department name.

Test your Programming skills with w3resource's quiz.

What is the difficulty level of this exercise?



SQL: Tips of the Day

"where 1=1" statement?

It's usually when folks build up SQL statements.

When you add and value = "Toyota" you don't have to worry about whether there is a condition before or just WHERE.

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