Questions: SQL Subqueries and CTEs

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

You run: SELECT * FROM employees WHERE id NOT IN (SELECT manager_id FROM departments). You expect some results, but get zero rows, even though many employees are not managers. What is the most likely cause?

ANOT IN cannot be used with subqueries — you must use a JOIN instead
BThe departments table has at least one NULL in the manager_id column, causing NOT IN to return no rows
CThe subquery returns too many rows, causing a performance timeout that returns no results
DNOT IN requires the subquery to be aliased with AS
Question 2 Multiple Choice

What distinguishes a correlated subquery from a non-correlated subquery?

AA correlated subquery appears in the FROM clause; a non-correlated subquery appears in the WHERE clause
BA correlated subquery references a column from the outer query and logically re-executes for each outer row; a non-correlated subquery executes once
CA correlated subquery always executes faster because the optimizer caches its result per outer row
DA correlated subquery is only valid inside a CTE; non-correlated subqueries can appear anywhere
Question 3 True / False

A subquery used as a derived table in the FROM clause must be given an alias.

TTrue
FFalse
Question 4 True / False

A correlated subquery typically executes once per outer row, making it slower than an equivalent JOIN regardless of the database optimizer used.

TTrue
FFalse
Question 5 Short Answer

Why should you use NOT EXISTS rather than NOT IN when your subquery might return NULL values?

Think about your answer, then reveal below.