Which SQL operator tests for the existence of rows returned by a subquery?

Study for the SQL Basics Test. Improve your knowledge with multiple choice questions and detailed explanations. Prepare effectively to master SQL concepts!

Multiple Choice

Which SQL operator tests for the existence of rows returned by a subquery?

Explanation:
Existence checks in SQL are handled by EXISTS, which tests whether a subquery yields any rows. If the inner query finds a matching row, EXISTS returns true and the outer row passes the filter; if no rows are produced, it returns false. This makes EXISTS ideal for checking the presence of related data without needing actual values and it can work with correlated subqueries, allowing the engine to stop as soon as a first match is found. For comparison, IN looks for membership in the set produced by the subquery, which can behave differently when NULLs are involved. LIKE compares a string to a pattern, and BETWEEN checks whether a value lies within a range; neither is about testing the existence of rows from a subquery. Example: SELECT * FROM employees e WHERE EXISTS (SELECT 1 FROM payroll p WHERE p.employee_id = e.id);

Existence checks in SQL are handled by EXISTS, which tests whether a subquery yields any rows. If the inner query finds a matching row, EXISTS returns true and the outer row passes the filter; if no rows are produced, it returns false. This makes EXISTS ideal for checking the presence of related data without needing actual values and it can work with correlated subqueries, allowing the engine to stop as soon as a first match is found. For comparison, IN looks for membership in the set produced by the subquery, which can behave differently when NULLs are involved. LIKE compares a string to a pattern, and BETWEEN checks whether a value lies within a range; neither is about testing the existence of rows from a subquery. Example: SELECT * FROM employees e WHERE EXISTS (SELECT 1 FROM payroll p WHERE p.employee_id = e.id);

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy