SQL Exercises

SQL Server: Intermediate SQL Subqueries Exercises

0 Exercises
~0 min

This guide is specifically for SQL Server syntax.

Intermediate-level SQL Subqueries practice exercises with solutions.

Exercise 1

Question: Find employees who earn more than the average salary.

SELECT name, salary FROM employees WHERE salary > (SELECT AVG(salary) FROM employees);

A scalar subquery returns a single value and can be used with comparison operators in WHERE clause.

Exercise 2

Question: Find products that have never been ordered.

SELECT name FROM products WHERE id NOT IN (SELECT DISTINCT product_id FROM order_items);

Subquery with NOT IN finds values that don't exist in another table's results.


SQL Server-Specific Notes

This page covers SQL Server syntax. Other databases may have different syntax for similar operations.

Related Content

From Our Blog

Ready for more practice?

Join SQL Mastery and get access to interactive exercises, quizzes, and more.