Which SQL operator is used to filter rows by checking whether a value matches…
2023
Which SQL operator is used to filter rows by checking whether a value matches any value in a specified list?
- A.
BETWEEN
- B.
IN
- C.
LIKE
- D.
EXISTS
- E.
DISTINCT
Attempted by 118 students.
Show answer & explanation
Correct answer: B
Concept
SQL provides several comparison and filtering operators for the WHERE clause. The membership operator IN tests whether a single value equals any value within an explicitly supplied set or list, e.g. WHERE col IN (v1, v2, v3). It is logically equivalent to a chain of OR equality tests (col = v1 OR col = v2 OR col = v3).
Application
The stem asks for the operator that filters rows by checking whether a value matches any value in a specified list. This is exactly the membership test, so the operator is IN. A query such as SELECT * FROM emp WHERE dept IN ('HR','IT','Finance') returns every row whose dept equals one of the listed values.
Contrast with the other operators
BETWEEN— tests a value against a continuous range with two bounds (col BETWEEN low AND high), not against a discrete list.LIKE— performs pattern matching on strings using wildcards (%,_), not list membership.EXISTS— returns true if a correlated subquery yields at least one row; it checks existence of rows, not equality with listed literals.DISTINCT— removes duplicate rows from a result set; it is not a row-filtering predicate at all.