MySQL Subquery - Exercises, Practice, Solution
MySQL Subquery [22 exercises with solution]
1. Write a query to find the name (first_name, last_name) and the salary of the employees who have a higher salary than the employee whose last_name='Bull'. Go to the editor
Sample table: employees
2. Write a query to find the name (first_name, last_name) of all employees who works in the IT department. Go to the editor
Sample table: employees
3. Write a query to find the name (first_name, last_name) of the employees who have a manager and worked in a USA based department. Go to the editor
Hint : Write single-row and multiple-row subqueries
Sample table: employees
Sample table: departments
Sample table: locations
4. Write a query to find the name (first_name, last_name) of the employees who are managers. Go to the editor
Sample table: employees
5. Write a query to find the name (first_name, last_name), and salary of the employees whose salary is greater than the average salary. Go to the editor
Sample table: employees
6. Write a query to find the name (first_name, last_name), and salary of the employees whose salary is equal to the minimum salary for their job grade. Go to the editor
Sample table: employees
Sample table: jobs
7. Write a query to find the name (first_name, last_name), and salary of the employees who earns more than the average salary and works in any of the IT departments. Go to the editor
Sample table: employees
Sample table: departments
8. Write a query to find the name (first_name, last_name), and salary of the employees who earns more than the earning of Mr. Bell. Go to the editor
Sample table: employees
Sample table: departments
9. Write a query to find the name (first_name, last_name), and salary of the employees who earn the same salary as the minimum salary for all departments. Go to the editor
Sample table: employees
Sample table: departments
10. Write a query to find the name (first_name, last_name), and salary of the employees whose salary is greater than the average salary of all departments. Go to the editor
Sample table: employees
11. Write a query to find the name (first_name, last_name) and salary of the employees who earn a salary that is higher than the salary of all the Shipping Clerk (JOB_ID = 'SH_CLERK'). Sort the results of the salary of the lowest to highest. Go to the editor
Sample table: employees
12. Write a query to find the name (first_name, last_name) of the employees who are not supervisors. Go to the editor
Sample table: employees
13. Write a query to display the employee ID, first name, last name, and department names of all employees. Go to the editor
Sample table: employees
Sample table: departments
14. Write a query to display the employee ID, first name, last name, salary of all employees whose salary is above average for their departments. Go to the editor
Sample table: employees
Sample table: departments
15. Write a query to fetch even numbered records from employees table. Go to the editor
Sample table: employees
16. Write a query to find the 5th maximum salary in the employees table. Go to the editor
Sample table: employees
17. Write a query to find the 4th minimum salary in the employees table. Go to the editor
Sample table: employees
18. Write a query to select last 10 records from a table. Go to the editor
Sample table: employees
19. Write a query to list the department ID and name of all the departments where no employee is working. Go to the editor
Sample table: employees
Sample table: departments
20. Write a query to get 3 maximum salaries. Go to the editor
Sample table: employees
21. Write a query to get 3 minimum salaries. Go to the editor
Sample table: employees
22. Write a query to get nth max salaries of employees. Go to the editor
Sample table: employees
More to Come !
Structure of 'hr' database:
MySQL Code Editor:
Write your query in right panel and click Run button to execute.
Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework