Examveda

Which operators test whether a subquery returns any rows?

A. IN and NOT IN

B. EXISTS and NOT EXISTS

C. PRESENT

D. ABSENT

Answer: Option B

Solution (By Examveda Team)

This question is about how we check if a smaller query (called a subquery) finds any matching data. Think of it like searching for a specific book in a library.

Option A: IN and NOT IN
These operators check if a value exists *within* a set of values returned by the subquery. They don't directly tell you if the subquery found *anything* at all.

Option B: EXISTS and NOT EXISTS
These are the key operators for checking if a subquery returns any rows!

Option C: PRESENT
This isn't a standard MySQL operator.

Option D: ABSENT
This also isn't a standard MySQL operator.

The Correct Answer is: Option B: EXISTS and NOT EXISTS

Why?
* EXISTS checks if the subquery returns at least one row. * NOT EXISTS checks if the subquery returns zero rows.

Example:
Let's say you have a table of students and another table of courses. You want to find students who are *not* enrolled in any courses. You could use NOT EXISTS to check if a student has any matching rows in the courses table.

This Question Belongs to MySQL >> MySQL Miscellaneous

Join The Discussion

Related Questions on MySQL Miscellaneous