SQL Practice Logo

SQLPractice Online

Pattern Matching (LIKE, REGEX): Interview

Module: Advanced Filtering

What is the difference between % and _ wildcards in LIKE?

% matches any sequence of characters (including zero characters). _ matches exactly one character. Use % for variable-length patterns, _ for fixed-length patterns.

When should you use REGEX instead of LIKE?

Use REGEX for complex patterns like email validation, phone number formats, or data extraction. Use LIKE for simple prefix/suffix/contains searches. REGEX is more powerful but slower.

Find customers with names starting with J and ending with n

SELECT * FROM customers WHERE name LIKE 'J%n';

J% matches names starting with J, %n matches names ending with n. Combined pattern matches both conditions.