Recall & Review
beginner
What does the EXISTS operator do in SQL?
EXISTS checks if a subquery returns any rows. It returns TRUE if the subquery has at least one row, otherwise FALSE.
Click to reveal answer
beginner
Write a simple example of a query using EXISTS.
SELECT * FROM Customers WHERE EXISTS (SELECT 1 FROM Orders WHERE Orders.CustomerID = Customers.ID);<br>This returns customers who have at least one order.
Click to reveal answer
intermediate
How is EXISTS different from IN in SQL?
EXISTS checks for the presence of rows and stops at the first match, making it efficient for some cases. IN compares values and may scan more rows.
Click to reveal answer
intermediate
Can EXISTS subquery refer to the outer query tables?
Yes, EXISTS subqueries often use columns from the outer query to filter results, making them correlated subqueries.
Click to reveal answer
intermediate
Why might you use EXISTS instead of JOIN?
EXISTS is useful when you only want to check if related rows exist, not to retrieve them. It can be faster and clearer for existence checks.
Click to reveal answer
What does the EXISTS operator return if the subquery finds no rows?
✗ Incorrect
EXISTS returns FALSE if the subquery returns zero rows.
Which of the following is a valid use of EXISTS?
✗ Incorrect
Option D correctly uses EXISTS with a subquery that relates to the outer query.
EXISTS subqueries are usually:
✗ Incorrect
EXISTS subqueries often refer to outer query columns, making them correlated.
Which is true about EXISTS performance?
✗ Incorrect
EXISTS stops as soon as it finds one matching row, which can improve performance.
What does this query do? SELECT * FROM Products WHERE EXISTS (SELECT 1 FROM Orders WHERE Orders.ProductID = Products.ID);
✗ Incorrect
It returns products that have at least one matching order.
Explain how the EXISTS operator works in SQL and give a simple example.
Think about checking if something exists before selecting.
You got /3 concepts.
Describe the difference between EXISTS and IN operators and when you might prefer EXISTS.
Consider performance and purpose of each operator.
You got /4 concepts.