SQL Database Subquery Logic Quiz
A 35-question quiz exploring basic subqueries, correlated subqueries, filtering, comparisons, scalar subqueries, and nested query reasoning.
Question 1
A team wants to filter products whose price is above the average price of all products. What type of subquery fits this requirement?
Question 2
A user wants to show all customers who have placed at least one order. They decide to use a subquery that checks for matching customer IDs. Which subquery style typically works here?
Question 3
A developer wants to find employees who earn more than the average salary for their own department. This comparison depends on each row being evaluated separately. What kind of subquery does this require?
Question 4
A system checks whether a product appears in any order before allowing deletion. Which subquery style supports this dependency check most naturally?
Question 5
A designer uses a subquery to pull the highest rating from the ratings table and then selects all items equal to that value. What does this indicate about the subquery type?
Question 6
A query retrieves users whose account balance exceeds all balances in a related table. Which operator pairs correctly with a subquery for this logic?
Question 7
A team wants to show all products that have never been ordered. Which subquery technique helps determine such missing relationships?
Question 8
A reviewer compares each employee’s, rating with the maximum rating in their own team. Which style must be used to reference the team_id inside the subquery?
Question 9
A query asks for all customers whose total orders exceed the total orders of customer ID 5. What shape of subquery supports this comparison?
Question 10
A user wants to identify departments where at least one employee has salary below a threshold. Which subquery pattern helps detect this?
Question 11
A store wants to find items priced above all items in another category. Which keyword supports multi-row comparison using a subquery?
Question 12
A recruiter wants candidates whose score is higher than at least one score in another tracking table. Which keyword applies?
Question 13
A user selects products whose category appears in a specific list inside a subquery. What typical operator supports this?
Question 14
A query finds employees whose salaries exceed the department average. Which dependency makes a correlated subquery necessary?
Question 15
A manager wants to list employees whose salary is the minimum within their department. Which technique retrieves one minimum value per department per employee row?
Question 16
An analyst checks whether a value exists in a related table without needing the returned rows. Which subquery structure is most efficient?
Question 17
A subquery attempts to return multiple rows during a comparison that expects a single value. What error or issue does this typically cause?
Question 18
What does this subquery retrieve for comparison?
SELECT * FROM products
WHERE price > (SELECT AVG(price) FROM products);Question 19
This query looks for customers with at least one order. What does the subquery return?
SELECT * FROM customers
WHERE id IN (SELECT customer_id FROM orders);Question 20
What type of subquery is being used here?
SELECT name FROM employees e
WHERE salary > (
SELECT AVG(salary)
FROM employees
WHERE department_id = e.department_id
);Question 21
This query selects items whose category exists in the categories table. Which logic is applied?
SELECT name FROM items
WHERE category_id IN (SELECT id FROM categories);Question 22
This subquery checks for the presence of matching rows. What keyword indicates this?
SELECT * FROM products p
WHERE EXISTS (
SELECT 1 FROM orders o
WHERE o.product_id = p.id
);Question 23
What does this query return?
SELECT * FROM employees
WHERE department_id NOT IN (
SELECT id FROM departments WHERE active = false
);Question 24
Why is this subquery correlated?
SELECT name FROM products p
WHERE price > (
SELECT AVG(price) FROM products
WHERE category_id = p.category_id
);Question 25
What comparison is being made here?
SELECT * FROM orders
WHERE total > ALL (
SELECT total FROM orders WHERE customer_id = 5
);Question 26
What does ANY mean in this context?
SELECT * FROM users
WHERE score > ANY (SELECT score FROM archived_scores);Question 27
What key behavior is shown here?
SELECT * FROM posts p
WHERE NOT EXISTS (
SELECT 1 FROM comments c
WHERE c.post_id = p.id
);Question 28
Which value does this scalar subquery provide?
SELECT name FROM employees
WHERE salary = (
SELECT MAX(salary) FROM employees
);Question 29
This correlated subquery compares rows by department. What does it compute?
SELECT name FROM employees e
WHERE salary < (
SELECT MIN(salary) FROM employees
WHERE department_id = e.department_id
);Question 30
What filtering pattern does this show?
SELECT * FROM books
WHERE id NOT IN (
SELECT book_id FROM rentals
);Question 31
What type of result does this subquery provide?
SELECT customer_id FROM orders
WHERE total > (
SELECT AVG(total) FROM orders
);Question 32
This correlated subquery references the outer query. What does it achieve?
SELECT name FROM stores s
WHERE rating > (
SELECT AVG(rating) FROM stores
WHERE city = s.city
);Question 33
What does this query return?
SELECT * FROM items i
WHERE EXISTS (
SELECT 1 FROM inventory inv
WHERE inv.item_id = i.id AND inv.stock > 0
);Question 34
What is the meaning of this comparison?
SELECT * FROM scores
WHERE value <= ALL (
SELECT value FROM scores
);Question 35
What is this subquery computing for comparison?
SELECT name FROM authors a
WHERE books_written > (
SELECT AVG(books_written) FROM authors
);