In SQL, does the LIKE operator in a WHERE clause select a numeric or date “range of values,” similar to BETWEEN?

Difficulty: Easy

Correct Answer: Does not apply — LIKE performs pattern matching on text

Explanation:

Introduction / Context:This clarifies the distinct purposes of LIKE and BETWEEN in SQL filtering. LIKE is about pattern matching; BETWEEN is about numeric/date (or ordered) ranges.

Given Data / Assumptions:

  • LIKE uses wildcards such as % and _ to match character patterns.
  • BETWEEN specifies inclusive lower and upper bounds for ordered types.
  • Some DBMSs allow LIKE on text representations of numbers/dates, but that is not range logic.

Concept / Approach:LIKE compares strings according to patterns. It is not a numeric comparator and does not interpret ranges. To select numeric/date ranges, use comparison operators (<, <=, >, >=) or BETWEEN. For more complex string sets, consider regular expressions if supported.

Step-by-Step Solution:Recognize the question conflates pattern matching with range checks.Recall: LIKE 'A%' finds strings beginning with A; BETWEEN 5 AND 10 finds numbers 5 through 10.Conclude LIKE is not a range operator.

Verification / Alternative check:Test WHERE col LIKE '1%' versus WHERE col BETWEEN 10 AND 19; these produce different results, especially for multi-digit values.

Why Other Options Are Wrong:Wildcards do not convert LIKE into numeric/date range logic. ORDER BY does not change predicate semantics.

Common Pitfalls:Lexicographic string comparisons can appear to mimic numeric ranges but break for differing lengths (e.g., '100' < '20' lexicographically). Always use numeric types for numeric ranges.

Final Answer:Does not apply — LIKE performs pattern matching on text

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion