SQL Database Subquery Logic Quiz

SQL Database
0 Passed
0% acceptance

A 35-question quiz exploring basic subqueries, correlated subqueries, filtering, comparisons, scalar subqueries, and nested query reasoning.

35 Questions
~70 minutes
1

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?

A
A scalar subquery returning a single average value
B
A correlated row-by-row subquery
C
A multi-table join only
D
A UNION comparison
2

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?

A
IN with a list of customer IDs from the orders table
B
A CHECK constraint
C
A DEFAULT lookup
D
A BETWEEN numeric rule
3

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?

A
Correlated subquery using department_id
B
Simple scalar subquery
C
UNION ALL construct
D
Self join only
4

Question 4

A system checks whether a product appears in any order before allowing deletion. Which subquery style supports this dependency check most naturally?

A
EXISTS-based subquery
B
Scalar MAX subquery
C
UNION set list
D
GROUP BY only
5

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?

A
A scalar subquery returning a single maximum value
B
A correlated comparison per-row
C
A table-altering expression
D
A UNION query merging rows
6

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?

A
>
B
BETWEEN
C
LIKE
D
OFFSET
7

Question 7

A team wants to show all products that have never been ordered. Which subquery technique helps determine such missing relationships?

A
NOT EXISTS
B
BETWEEN
C
LIKE
D
GROUP BY only
8

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?

A
Correlated subquery
B
Independent scalar subquery
C
UNION-based join
D
Cross join only
9

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?

A
Scalar subquery computing customer 5’s total
B
EXISTS subquery
C
UNION of all totals
D
CHECK constraint
10

Question 10

A user wants to identify departments where at least one employee has salary below a threshold. Which subquery pattern helps detect this?

A
EXISTS
B
DISTINCT ON
C
GROUP BY only
D
BETWEEN operator
11

Question 11

A store wants to find items priced above all items in another category. Which keyword supports multi-row comparison using a subquery?

A
ALL
B
IN
C
OFFSET
D
UNION ALL
12

Question 12

A recruiter wants candidates whose score is higher than at least one score in another tracking table. Which keyword applies?

A
ANY
B
LIKE
C
BETWEEN
D
UNION
13

Question 13

A user selects products whose category appears in a specific list inside a subquery. What typical operator supports this?

A
IN
B
NOT LIKE
C
||
D
AS
14

Question 14

A query finds employees whose salaries exceed the department average. Which dependency makes a correlated subquery necessary?

A
The comparison depends on each employee’s department
B
The comparison depends on fixed constants
C
The subquery is unrelated to outer fields
D
The database disallows joins
15

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?

A
Correlated aggregate subquery
B
UNION ALL merge
C
Scalar fixed constant
D
OFFSET-based filtering
16

Question 16

An analyst checks whether a value exists in a related table without needing the returned rows. Which subquery structure is most efficient?

A
EXISTS
B
IN
C
MIN(...)
D
LIKE
17

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?

A
Scalar subquery returning multiple rows
B
Syntax error only
C
JOIN explosion
D
Foreign key mismatch
18

Question 18

What does this subquery retrieve for comparison?

sql
SELECT * FROM products
WHERE price > (SELECT AVG(price) FROM products);
A
A single average price value
B
A list of prices
C
A table of products
D
A category name
19

Question 19

This query looks for customers with at least one order. What does the subquery return?

sql
SELECT * FROM customers
WHERE id IN (SELECT customer_id FROM orders);
A
A list of customer IDs
B
A single average value
C
All customer rows
D
A boolean
20

Question 20

What type of subquery is being used here?

sql
SELECT name FROM employees e
WHERE salary > (
  SELECT AVG(salary)
  FROM employees
  WHERE department_id = e.department_id
);
A
Correlated subquery
B
Scalar independent subquery
C
UNION
D
EXISTS only
21

Question 21

This query selects items whose category exists in the categories table. Which logic is applied?

sql
SELECT name FROM items
WHERE category_id IN (SELECT id FROM categories);
A
IN with a subquery-returned list
B
Scalar comparison
C
UNION collapse
D
NOT EXISTS
22

Question 22

This subquery checks for the presence of matching rows. What keyword indicates this?

sql
SELECT * FROM products p
WHERE EXISTS (
  SELECT 1 FROM orders o
  WHERE o.product_id = p.id
);
A
EXISTS
B
IN
C
ANY
D
ALL
23

Question 23

What does this query return?

sql
SELECT * FROM employees
WHERE department_id NOT IN (
  SELECT id FROM departments WHERE active = false
);
A
Employees not in inactive departments
B
Employees only in inactive departments
C
All employees regardless of department
D
Only departments
24

Question 24

Why is this subquery correlated?

sql
SELECT name FROM products p
WHERE price > (
  SELECT AVG(price) FROM products
  WHERE category_id = p.category_id
);
A
It references p.category_id from the outer query
B
It returns multiple rows
C
It uses GROUP BY only
D
It uses IN
25

Question 25

What comparison is being made here?

sql
SELECT * FROM orders
WHERE total > ALL (
  SELECT total FROM orders WHERE customer_id = 5
);
A
Orders greater than all totals for customer 5
B
Orders equal to max total
C
Orders only for customer 5
D
A boolean state only
26

Question 26

What does ANY mean in this context?

sql
SELECT * FROM users
WHERE score > ANY (SELECT score FROM archived_scores);
A
score must exceed at least one archived score
B
score must exceed all scores
C
score must equal a score
D
score must be null
27

Question 27

What key behavior is shown here?

sql
SELECT * FROM posts p
WHERE NOT EXISTS (
  SELECT 1 FROM comments c
  WHERE c.post_id = p.id
);
A
Returns posts with no comments
B
Returns posts with comments
C
Deletes comments
D
Computes totals
28

Question 28

Which value does this scalar subquery provide?

sql
SELECT name FROM employees
WHERE salary = (
  SELECT MAX(salary) FROM employees
);
A
The highest salary
B
A list of salaries
C
Total count
D
A boolean
29

Question 29

This correlated subquery compares rows by department. What does it compute?

sql
SELECT name FROM employees e
WHERE salary < (
  SELECT MIN(salary) FROM employees
  WHERE department_id = e.department_id
);
A
Employees earning below their department minimum
B
Employees earning above average
C
All employees
D
Only department minimum rows
30

Question 30

What filtering pattern does this show?

sql
SELECT * FROM books
WHERE id NOT IN (
  SELECT book_id FROM rentals
);
A
Books that have never been rented
B
Books with many rentals
C
Books rented today
D
Books with negative stock
31

Question 31

What type of result does this subquery provide?

sql
SELECT customer_id FROM orders
WHERE total > (
  SELECT AVG(total) FROM orders
);
A
A scalar average value
B
A list of totals
C
A boolean
D
A product ID
32

Question 32

This correlated subquery references the outer query. What does it achieve?

sql
SELECT name FROM stores s
WHERE rating > (
  SELECT AVG(rating) FROM stores
  WHERE city = s.city
);
A
Compares each store with the average rating of its city
B
Compares all stores globally
C
Filters only on fixed values
D
Removes foreign keys
33

Question 33

What does this query return?

sql
SELECT * FROM items i
WHERE EXISTS (
  SELECT 1 FROM inventory inv
  WHERE inv.item_id = i.id AND inv.stock > 0
);
A
Items with available stock
B
Items with no stock
C
All items regardless of inventory
D
A single stock value
34

Question 34

What is the meaning of this comparison?

sql
SELECT * FROM scores
WHERE value <= ALL (
  SELECT value FROM scores
);
A
Values that are less than or equal to the minimum score
B
Values greater than average
C
Values matching every score
D
Values that are NULL
35

Question 35

What is this subquery computing for comparison?

sql
SELECT name FROM authors a
WHERE books_written > (
  SELECT AVG(books_written) FROM authors
);
A
The overall average number of books written
B
A list of all authors
C
A boolean value only
D
The minimum books_written

QUIZZES IN SQL Database