w3resource
SQL exercises

SQL Subquery Exercises: Display the first and last name, salary, and department ID for all those employees who work in that department where the employee works who hold the ID 201

SQL SUBQUERY: Exercise-39 with Solution

Write a query in SQL to display the first and last name, salary, and department ID for all those employees who work in that department where the employee works who hold the ID 201.

Sample table: employees


Sample Solution:

SELECT first_name, last_name, salary, department_id 
 FROM employees 
  WHERE department_id = 
     (SELECT department_id 
       FROM employees 
        WHERE employee_id = 201);

Sample Output:

first_name	last_name	salary	department_id
Michael		Hartstein	13000.00	20
Pat		Fay		6000.00		20

Practice Online


Query Visualization:

Duration:

Query visualization of Display the first and last name, salary, and department ID for all those employees who work in that department where the employee works who hold the ID 201 - Duration

Rows:

Query visualization of Display the first and last name, salary, and department ID for all those employees who work in that department where the employee works who hold the ID 201 - Rows

Cost:

Query visualization of Display the first and last name, salary, and department ID for all those employees who work in that department where the employee works who hold the ID 201 - Cost

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

Previous: Write a query in SQL to display the department name and Id for all departments where they located, that Id is equal to the Id for the location where department number 30 is located.
Next: Write a query in SQL to display the first and last name, salary, and department ID for those employees whose salary is equal to the salary of the employee who works in that department which ID is 40.

What is the difficulty level of this exercise?



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