SQL Practice Logo

SQLPractice Online

Pattern Matching (LIKE, REGEX): Mistakes

Module: Advanced Filtering

SELECT * FROM customers WHERE name LIKE 'John';

SELECT * FROM customers WHERE name LIKE 'John%' OR name = 'John';

LIKE 'John' only matches exactly "John", not "Johnson". Use % wildcard or = for exact match.

Always use wildcards with LIKE, or use = for exact matches

High

LIKE without wildcards matches exact string only

SELECT * FROM products WHERE sku LIKE '%PROD%';

SELECT * FROM products WHERE sku LIKE 'PROD%';

Leading % forces full table scan. If searching for prefix, remove leading wildcard.

Avoid leading wildcards when possible for better performance

Medium

Leading wildcard prevents index usage