w3resource
SQL exercises

SQL Subquery Exercises: 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

SQL SUBQUERY: Exercise-40 with Solution

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.

Sample table: employees


Sample Solution:

SELECT first_name, last_name, salary, department_id 
 FROM employees
  WHERE salary IN (
                   SELECT salary 
                     FROM employees 
                       WHERE department_id = 40);

Sample Output:

first_name	last_name	salary	department_id
Shanta		Vollman		6500.00		50
Susan		Mavris		6500.00		40

Practice Online


Query Visualization:

Duration:

Query visualization of 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 - Duration

Rows:

Query visualization of 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 - Rows

Cost:

Query visualization of 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 - Cost

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

Previous: 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.
Next: Write a query in SQL to display the first and last name, and department code for all employees who work in the department Marketing.

What is the difficulty level of this exercise?



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