PostgreSQL Subquery - Exercises, Practice, Solution
PostgreSQL Subquery [21 exercises with solution]
1. Write a query to find the first_name, last_name and salaries of the employees who have a higher salary than the employee whose last_name is Bull.
Sample table: employees
2. Write a SQL subquery to find the first_name and last_name of all employees who works in the IT department.
Sample table: employees
3. Write a SQL subquery to find the first_name and last_name of the employees under a manager who works for a department based in the United States.
Hint : Write single-row and multiple-row subqueries
Sample table: employees
Sample table: departments
Sample table: locations
4. Write a SQL subquery to find the first_name and last_name of the employees who are working as a manager.
Sample table: employees
5. Write a SQL subquery to find the first_name, last_name and salary, which is greater than the average salary of the employees.
Sample table: employees
6. Write a SQL subquery to find the first_name, last_name and salary, which is equal to the minimum salary for this post, he/she is working on.
Sample table: employees
Sample table: jobs
7. Write a SQL Subquery to find the first_name, last_name and salary of the employees who earn more than the average salary and works in any of the IT departments.
Sample table: employees
Sample table: departments
8. Write a SQL subquery to find the first_name, last_name and salary of the employees who draw a more salary than the employee, which the last name is Bell.
Sample table: employees
Sample table: departments
9. Write a SQL subquery to find all the information of the employees who draws the same salary as the minimum salary for all departments.
Sample table: employees
Sample table: departments
10. Write a SQL subquery to find all the information of the employees whose salary greater than the average salary of all departments.
Sample table: employees
11. Write a subquery to find the first_name, last_name, job_id and salary of the employees who draws a salary that is higher than the salary of all the Shipping Clerk (JOB_ID = 'SH_CLERK'). Sort the results on salary from the lowest to highest.
Sample table: employees
12. Write a query to find the names (first_name, last_name) of the employees who are not supervisors.
Sample table: employees
13. Write a SQL subquery to find the employee ID, first name, last name and department names of all employees.
Sample table: employees
Sample table: departments
14. Write a SQL subquery to find the employee ID, first name, last name and salary of all employees whose salary is above the average salary for their departments.
Sample table: employees
Sample table: departments
15. Write a subquery to find the 5th maximum salary of all salaries.
Sample table: employees
16. Write a subquery to find the 4th minimum salary of all the salaries.
Sample table: employees
17. Write a subquery to select last 10 records from a table.
Sample table: employees
Sample table: departments
18. Write a query to list department number, the name for all the departments in which there are no employees in the department.
Sample table: employees
Sample table: departments
19. Write a query to get three maximum salaries.
Sample table: employees
20. Write a query to get three minimum salaries.
Sample table: employees
21. Write a query to get nth max salaries of employees.
Sample table: employees
... More
Structure of 'hr' database:
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/postgresql-exercises/subquery/index.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics