Editor

SQL practice problems

Write a query for each problem, check it against the answer in your browser, and see why it works.

50 shown

  1. Students in class 12SELECT basics, WHERESchoolEasy
  2. Students without an email addressNULL values, WHERESchoolEasy
  3. Cities the students come fromDISTINCT, ORDER BYSchoolEasy
  4. The three oldest studentsORDER BY, LIMITSchoolEasy
  5. Students in each class and sectionGROUP BY, COUNT, SUM, AVGSchoolEasy
  6. Add a new studentINSERT, NULL valuesSchoolEasy
  7. Delete enrollments that have no marksDELETE, NULL valuesSchoolEasy
  8. Products that cost less than 20WHERE, ORDER BYOnline shopEasy
  9. Customers in India with their cityString functions, WHERE, SELECT basicsOnline shopEasy
  10. Number of orders in each statusGROUP BY, COUNT, SUM, AVGOnline shopEasy
  11. The five most expensive productsORDER BY, LIMITOnline shopEasy
  12. Orders placed in 2026Date functions, WHEREOnline shopEasy
  13. Product categoriesDISTINCT, SELECT basicsOnline shopEasy
  14. Raise the prices of stationeryUPDATE, WHEREOnline shopEasy
  15. Projects that are still runningNULL values, WHERECompanyEasy
  16. Employees and their departmentsJOIN, ORDER BYCompanyEasy
  17. Salary summaryCOUNT, SUM, AVGCompanyEasy
  18. Job titles in the companyDISTINCT, ORDER BYCompanyEasy
  19. Average marks in each courseJOIN, GROUP BY, COUNT, SUM, AVGSchoolMedium
  20. Students not enrolled in any courseLEFT JOIN, NULL valuesSchoolMedium
  21. Teachers and the courses they teachLEFT JOIN, ORDER BYSchoolMedium
  22. Courses with more than four studentsJOIN, GROUP BY, HAVINGSchoolMedium
  23. A grade for every markCASE, JOIN, NULL valuesSchoolMedium
  24. Enrollments per monthDate functions, GROUP BYSchoolMedium
  25. Create a table for clubsCREATE TABLE, INSERTSchoolMedium
  26. Totals of delivered ordersJOIN, GROUP BY, COUNT, SUM, AVGOnline shopMedium
  27. Products that were never orderedLEFT JOIN, SubqueriesOnline shopMedium
  28. Customers who spent more than 200JOIN, GROUP BY, HAVINGOnline shopMedium
  29. Price bands for productsCASEOnline shopMedium
  30. Customers who ordered in both 2025 and 2026UNION, INTERSECT, EXCEPT, Date functions, SubqueriesOnline shopMedium
  31. Products priced above the averageSubqueries, COUNT, SUM, AVGOnline shopMedium
  32. Delete the items of cancelled ordersDELETE, SubqueriesOnline shopMedium
  33. Employees and their managersSelf join, LEFT JOINCompanyMedium
  34. Hours logged on each projectLEFT JOIN, GROUP BY, NULL valuesCompanyMedium
  35. Departments with an average salary above 110000GROUP BY, HAVING, JOINCompanyMedium
  36. How many days finished projects tookDate functionsCompanyMedium
  37. Engineers who are on no projectUNION, INTERSECT, EXCEPT, JOINCompanyMedium
  38. Email addresses for the sales teamString functions, JOINCompanyMedium
  39. A raise for the London officesUPDATE, SubqueriesCompanyMedium
  40. A table of finished projectsCREATE TABLE, NULL valuesCompanyMedium
  41. Rank the students in each courseWindow functions, JOINSchoolHard
  42. The top student in each courseSubqueries, JOINSchoolHard
  43. Running total of revenue in 2025Window functions, WITH (CTE)Online shopHard
  44. Monthly revenue and the change from the month beforeWindow functions, WITH (CTE), Date functionsOnline shopHard
  45. The best-selling product in each categoryWindow functions, WITH (CTE), JOINOnline shopHard
  46. Customers who never received an orderSubqueries, LEFT JOINOnline shopHard
  47. The second highest salarySubqueries, COUNT, SUM, AVGCompanyHard
  48. Employees who earn more than their managerSelf joinCompanyHard
  49. Employees paid above their department averageSubqueries, JOINCompanyHard
  50. Departments with a payroll above averageWITH (CTE), GROUP BY, COUNT, SUM, AVGCompanyHard

To try queries of your own, open the online SQL compiler with the same databases.