w3resource
SQL exercises

SQL Subquery Exercises: Display the employee id, name, salary, department name and city for all the employees who gets the salary as the salary earn by the employee which is maximum within the joining person January 1st, 2002 and December 31st, 2003

SQL SUBQUERY: Exercise-34 with Solution

Write a query to display the employee id, name ( first name and last name ), salary, department name and city for all the employees who gets the salary as the salary earn by the employee which is maximum within the joining person January 1st, 2002 and December 31st, 2003.

Sample table: employees


Sample table: departments


Sample table: locations


Sample Solution:

SELECT a.employee_id, a.first_name, a.last_name, a.salary, b.department_name, c.city  
FROM employees a, departments b, locations c  
WHERE a.salary =  
(SELECT MAX(salary) 
FROM employees 
WHERE hire_date BETWEEN '01/01/2002' AND '12/31/2003') 
AND a.department_id=b.department_id 
AND b.location_id=c.location_id;

Sample Output:

employee_id	first_name	last_name	salary	department_name		city
100		Steven		King		24000.00	Executive	Seattle

Practice Online


Query Visualization:

Duration:

Query visualization of Display the employee id, name, salary, department name and city for all the employees who gets the salary as the salary earn by the employee which is maximum within the joining person January 1st, 2002 and December 31st, 2003 - Duration

Rows:

Query visualization of Display the employee id, name, salary, department name and city for all the employees who gets the salary as the salary earn by the employee which is maximum within the joining person January 1st, 2002 and December 31st, 2003 - Rows

Cost:

Query visualization of Display the employee id, name, salary, department name and city for all the employees who gets the salary as the salary earn by the employee which is maximum within the joining person January 1st, 2002 and December 31st, 2003 - Cost

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

Previous: Write a query to get the details of employees who manage a department.
Next: Write a query in SQL to display the department code and name for all departments which located in the city London.

What is the difficulty level of this exercise?



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