SQL practice problems
Write a query for each problem, check it against the answer in your browser, and see why it works.
50 shown
- Students in class 12SELECT basics, WHERESchoolEasy
- Students without an email addressNULL values, WHERESchoolEasy
- Cities the students come fromDISTINCT, ORDER BYSchoolEasy
- The three oldest studentsORDER BY, LIMITSchoolEasy
- Students in each class and sectionGROUP BY, COUNT, SUM, AVGSchoolEasy
- Add a new studentINSERT, NULL valuesSchoolEasy
- Delete enrollments that have no marksDELETE, NULL valuesSchoolEasy
- Products that cost less than 20WHERE, ORDER BYOnline shopEasy
- Customers in India with their cityString functions, WHERE, SELECT basicsOnline shopEasy
- Number of orders in each statusGROUP BY, COUNT, SUM, AVGOnline shopEasy
- The five most expensive productsORDER BY, LIMITOnline shopEasy
- Orders placed in 2026Date functions, WHEREOnline shopEasy
- Product categoriesDISTINCT, SELECT basicsOnline shopEasy
- Raise the prices of stationeryUPDATE, WHEREOnline shopEasy
- Projects that are still runningNULL values, WHERECompanyEasy
- Employees and their departmentsJOIN, ORDER BYCompanyEasy
- Salary summaryCOUNT, SUM, AVGCompanyEasy
- Job titles in the companyDISTINCT, ORDER BYCompanyEasy
- Average marks in each courseJOIN, GROUP BY, COUNT, SUM, AVGSchoolMedium
- Students not enrolled in any courseLEFT JOIN, NULL valuesSchoolMedium
- Teachers and the courses they teachLEFT JOIN, ORDER BYSchoolMedium
- Courses with more than four studentsJOIN, GROUP BY, HAVINGSchoolMedium
- A grade for every markCASE, JOIN, NULL valuesSchoolMedium
- Enrollments per monthDate functions, GROUP BYSchoolMedium
- Create a table for clubsCREATE TABLE, INSERTSchoolMedium
- Totals of delivered ordersJOIN, GROUP BY, COUNT, SUM, AVGOnline shopMedium
- Products that were never orderedLEFT JOIN, SubqueriesOnline shopMedium
- Customers who spent more than 200JOIN, GROUP BY, HAVINGOnline shopMedium
- Price bands for productsCASEOnline shopMedium
- Customers who ordered in both 2025 and 2026UNION, INTERSECT, EXCEPT, Date functions, SubqueriesOnline shopMedium
- Products priced above the averageSubqueries, COUNT, SUM, AVGOnline shopMedium
- Delete the items of cancelled ordersDELETE, SubqueriesOnline shopMedium
- Employees and their managersSelf join, LEFT JOINCompanyMedium
- Hours logged on each projectLEFT JOIN, GROUP BY, NULL valuesCompanyMedium
- Departments with an average salary above 110000GROUP BY, HAVING, JOINCompanyMedium
- How many days finished projects tookDate functionsCompanyMedium
- Engineers who are on no projectUNION, INTERSECT, EXCEPT, JOINCompanyMedium
- Email addresses for the sales teamString functions, JOINCompanyMedium
- A raise for the London officesUPDATE, SubqueriesCompanyMedium
- A table of finished projectsCREATE TABLE, NULL valuesCompanyMedium
- Rank the students in each courseWindow functions, JOINSchoolHard
- The top student in each courseSubqueries, JOINSchoolHard
- Running total of revenue in 2025Window functions, WITH (CTE)Online shopHard
- Monthly revenue and the change from the month beforeWindow functions, WITH (CTE), Date functionsOnline shopHard
- The best-selling product in each categoryWindow functions, WITH (CTE), JOINOnline shopHard
- Customers who never received an orderSubqueries, LEFT JOINOnline shopHard
- The second highest salarySubqueries, COUNT, SUM, AVGCompanyHard
- Employees who earn more than their managerSelf joinCompanyHard
- Employees paid above their department averageSubqueries, JOINCompanyHard
- 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.