SQL LIKE & Wildcards

Article Summary

The LIKE operator is used to search for patterns in text. It works with wildcards to match partial strings. πŸ”Ή Wildcards You Can Use Wildcard Meaning % Matches zero or more characters _ Matches exactly one character πŸ”Ή Examples with LIKE πŸ”Ή Case Sensitivity 🧠 Quick Recap Pattern Matches Example 'J%' John, Jack, Jenny '%son' […]

The LIKE operator is used to search for patterns in text. It works with wildcards to match partial strings.

πŸ”Ή Wildcards You Can Use

WildcardMeaning
%Matches zero or more characters
_Matches exactly one character

πŸ”Ή Examples with LIKE

-- Starts with 'A'
SELECT * FROM employees WHERE name LIKE 'A%';

-- Ends with 'n'
SELECT * FROM employees WHERE name LIKE '%n';

-- Contains 'ar'
SELECT * FROM employees WHERE name LIKE '%ar%';

-- Second letter is 'e'
SELECT * FROM employees WHERE name LIKE '_e%';

-- 5-letter names only
SELECT * FROM employees WHERE name LIKE '_____';

πŸ”Ή Case Sensitivity

  • MySQL: LIKE is case-insensitive by default (depends on collation)
  • PostgreSQL / SQL Server / Oracle: Usually case-sensitive
    • Use ILIKE in PostgreSQL for case-insensitive match

🧠 Quick Recap

PatternMatches Example
'J%'John, Jack, Jenny
'%son'Jason, Nelson
'__a%'Anna, Sara, Mark
'_____'Any 5-letter name

βœ… Great for flexible searches like names, emails, and codes

Was this helpful?