In SQL pattern matching, which keyword is used with wildcard characters (for example, % and _) to filter rows by a textual pattern?

Difficulty: Easy

Correct Answer: LIKE only

Explanation:


Introduction / Context:
Filtering text using patterns is a frequent requirement. In standard SQL, wildcards are applied with a specific predicate that understands special characters such as percent and underscore.



Given Data / Assumptions:

  • We want to match patterns like names starting with 'An%' or codes with single-character placeholders 'A_3'.
  • We are using standard SQL wildcards: % for any length, _ for a single character.
  • We are not using vendor-specific full-text search predicates.


Concept / Approach:
The keyword LIKE evaluates a string against a pattern containing wildcards. IN and NOT IN test membership in a list or subquery result and do not interpret wildcards. Some legacy dialects have a MATCHES operator, but it is not part of standard SQL.



Step-by-Step Solution:

Identify the need: pattern-based filtering.Apply LIKE with % or _ as needed, for example: WHERE name LIKE 'Ann%'.Exclude list-membership predicates that ignore wildcards.


Verification / Alternative check:
Run: SELECT * FROM t WHERE code LIKE 'A_3'; This returns rows where code has 'A', then any one character, then '3'.



Why Other Options Are Wrong:

  • IN / NOT IN: Compare whole values; wildcards are treated as ordinary characters.
  • MATCHES: Non-standard across engines; not the general SQL answer.


Common Pitfalls:
For case-insensitive matching, use functions or collations as appropriate. Avoid leading wildcards like '%term' on large tables without indexes suited for such searches.



Final Answer:
LIKE only

Discussion & Comments

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