w3resource logo
SQL Exercises

SQL Exercises, Practice, Solution - SORTING and FILTERING on HR Database

SQL [38 exercises with solution]

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

1. Write a query in SQL to display the full name (first and last name), and salary for those employees who earn below 6000.  Go to the editor

Sample table: employees

Click me to see the solution

2. Write a query in SQL to display the first and last_name, department number and salary for those employees who earn more than 8000.  Go to the editor

Sample table: employees

Click me to see the solution

3. Write a query in SQL to display the first and last name, and department number for all employees whose last name is “McEwen”.  Go to the editor

Sample table: employees

Click me to see the solution

4. Write a query in SQL to display all the information for all employees without any department number.  Go to the editor

Sample table: employees

Click me to see the solution

5. Write a query in SQL to display all the information about the department Marketing.  Go to the editor

Sample table: departments

Click me to see the solution

6. Write a query in SQL to display the full name (first and last), hire date, salary, and department number for those employees whose first name does not containing the letter M and make the result set in ascending order by department number.  Go to the editor

Sample table: employees

Click me to see the solution

7. Write a query in SQL to display all the information of employees whose salary is in the range of 8000 and 12000 and commission is not null or department number is except the number 40, 120 and 70 and they have been hired before June 5th, 1987. Go to the editor

Sample table: employees

Click me to see the solution

8. Write a query in SQL to display the full name (first and last name), and salary for all employees who does not earn any commission.  Go to the editor

Sample table: employees

Click me to see the solution

9. Write a query in SQL to display the full name (first and last), the phone number and email separated by hyphen, and salary, for those employees whose salary is within the range of 9000 and 17000. The column headings assign with Full_Name, Contact_Details and Remuneration respectively.  Go to the editor

Sample table: employees

Click me to see the solution

10. Write a query in SQL to display the first and last name, and salary for those employees whose first name is ending with the letter m.  Go to the editor

Sample table: employees

Click me to see the solution

11. Write a query in SQL to display the full name (first and last) name, and salary, for all employees whose salary is out of the range 7000 and 15000 and make the result set in ascending order by the full name.  Go to the editor

Sample table: employees

Click me to see the solution

12. Write a query in SQL to display the full name (first and last), job id and date of hire for those employees who was hired during November 5th, 2007 and July 5th, 2009. Go to the editor

Sample table: employees

Click me to see the solution

13. Write a query in SQL to display the the full name (first and last name), and department number for those employees who works either in department 70 or 90.  Go to the editor

Sample table: employees

Click me to see the solution

14. Write a query in SQL to display the full name (first and last name), salary, and manager number for those employees who is working under a manager.  Go to the editor

Sample table: employees

Click me to see the solution

15. Write a query in SQL to display all the information from Employees table for those employees who was hired before June 21st, 2002.  Go to the editor

Sample table: employees

Click me to see the solution

16. Write a query in SQL to display the first and last name, email, salary and manager ID, for those employees whose managers are hold the ID 120, 103 or 145.  Go to the editor

Sample table: employees

Click me to see the solution

17. Write a query in SQL to display all the information for all employees who have the letters D, S, or N in their first name and also arrange the result in descending order by salary.  Go to the editor

Sample table: employees

Click me to see the solution

18. Write a query in SQL to display the full name (first name and last name), hire date, commission percentage, email and telephone separated by '-', and salary for those employees who earn the salary above 11000 or the seventh digit in their phone number equals 3 and make the result set in a descending order by the first name.  Go to the editor

Sample table: employees

Click me to see the solution

19. Write a query in SQL to display the first and last name, and department number for those employees who holds a letter s as a 3rd character in their first name. Go to the editor

Sample table : employees

Click me to see the solution

20. Write a query in SQL to display the employee ID, first name, job id, and department number for those employees who is working except the departments 50,30 and 80.  Go to the editor

Sample table : employees

Click me to see the solution

21. Write a query in SQL to display the employee Id, first name, job id, and department number for those employees whose department number equals 30, 40 or 90.  Go to the editor

Sample table : employees

Click me to see the solution

22. Write a query in SQL to display the ID for those employees who did two or more jobs in the past.  Go to the editor

Sample table : job_history

Click me to see the solution

23. Write a query in SQL to display job ID, number of employees, sum of salary, and difference between highest salary and lowest salary for a job.  Go to the editor

Sample table : employees

Click me to see the solution

24. Write a query in SQL to display job ID for those jobs that were done by two or more for more than 300 days.  Go to the editor

Sample table : job_history

Click me to see the solution

25. Write a query in SQL to display the country ID and number of cities in that country we have.  Go to the editor

Sample table : loations

Click me to see the solution

26. Write a query in SQL to display the manager ID and number of employees managed by the manager.  Go to the editor

Sample table : employees

Click me to see the solution

27. Write a query in SQL to display the details of jobs in descending sequence on job title.  Go to the editor

Sample table : jobs

Click me to see the solution

28. Write a query in SQL to display the first and last name and date of joining of the employees who is either Sales Representative or Sales Man.  Go to the editor

Sample table : employees

Click me to see the solution

29. Write a query in SQL to display the average salary of employees for each department who gets a commission percentage.  Go to the editor

Sample table : employees

Click me to see the solution

30. Write a query in SQL to display those departments where any manager is managing 4 or more employees.  Go to the editor

Sample table : employees

Click me to see the solution

31. Write a query in SQL to display those departments where more than ten employees work who got a commission percentage.  Go to the editor

Sample table : employees

Click me to see the solution

32. Write a query in SQL to display the employee ID and the date on which he ended his previous job.  Go to the editor

Sample table : job_history

Click me to see the solution

33. Write a query in SQL to display the details of the employees who have no commission percentage and salary within the range 7000 to 12000 and works in that department which number is 50.  Go to the editor

Sample table : employees

Click me to see the solution

34. Write a query in SQL to display the job ID for those jobs which average salary is above 8000.  Go to the editor

Sample table : employees

Click me to see the solution

35. Write a query in SQL to display job Title, the difference between minimum and maximum salaries for those jobs which max salary within the range 12000 to 18000.  Go to the editor

Sample table : jobs

Click me to see the solution

36. Write a query in SQL to display all those employees whose first name or last name starts with the letter D.  Go to the editor

Sample table : employees

Click me to see the solution

37. Write a query in SQL to display the details of jobs which minimum salary is greater than 9000.  Go to the editor

Sample table : jobs

Click me to see the solution

38. Write a query in SQL to display those employees who joined after 7th September, 1987.  Go to the editor

Sample table : employees

Click me to see the solution

Practice Online