w3resource

SQLite Subquery - Exercises, Practice, Solution

SQLite Subquery [18 exercises with solution]

[An editor is available at the bottom of the page to write and execute the scripts. Go to the editor]

1. Write a query to find the names (first_name, last_name) and salaries of the employees who have a higher salary than the employee whose last_name='Bull'.

Sample table : employees


Click me to see the solution.

2. Write a query to find the names (first_name, last_name) of all employees who works in the IT department.

Sample table : employees


Click me to see the solution

3. Write a query to find the names (first_name, last_name) of the employees who have 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


Click me to see the solution

4. Write a query to find the names (first_name, last_name) of the employees who are managers.

Sample table : employees


Click me to see the solution

5. Write a query to find the names (first_name, last_name), the salary of the employees whose salary is greater than the average salary.

Sample table : employees


Click me to see the solution

6. Write a query to find the names (first_name, last_name), the salary of the employees whose salary is equal to the minimum salary for their job grade.

Sample table : employees


Sample table: jobs


Click me to see the solution

7. Write a query to find the names (first_name, last_name), the salary of the employees who earn more than the average salary and who works in any of the IT departments.

Sample table : employees


Sample table : departments


Click me to see the solution

8. Write a query to find the names (first_name, last_name), the salary of the employees who earn more than Mr. Bell.

Sample table : employees


Sample table : departments


Click me to see the solution

9. Write a query to find the names (first_name, last_name), the salary of the employees who earn the same salary as the minimum salary for all departments.

Sample table : employees


Sample table : departments


Click me to see the solution

10. Write a query to find the names (first_name, last_name) of the employees who are not supervisors.

Sample table : employees


Click me to see the solution

11. Write a query to display the employee ID, first name, last names, salary of all employees whose salary is above average for their departments.

Sample table : employees

Sample table : departments

Click me to see the solution

12. Write a query to find the 5th maximum salary in the employees table.

Sample table : employees

Click me to see the solution

13. Write a query to find the 4th minimum salary in the employees table.

Sample table : employees


Click me to see the solution

14. Write a query to select last 10 records from a table.

Sample table : employees


Click me to see the solution

15. Write a query to list department number, name for all the departments in which there are no employees in the department.

Sample table : employees


Sample table : departments


Click me to see the solution

16. Write a query to get 3 maximum salaries.

Sample table : employees


Click me to see the solution

17. Write a query to get 3 minimum salaries.

Sample table : employees


Click me to see the solution

18. Write a query to get nth max salaries of employees.

Sample table : employees


Click me to see the solution

...More

The structure of 'hr' database :

hr database


Become a Patron!

Follow us on Facebook and Twitter for latest update.

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/sqlite-exercises/sqlite-subquery-exercises.php