LIKE Patterns and Wildcards
Use LIKE with % and _ wildcards, understand case sensitivity, and prefer ILIKE on PostgreSQL for case-insensitive matching.
What LIKE Does
LIKE matches a string against a pattern. Two wildcards:
%— any sequence (including empty)_— exactly one character
Simple Examples
Match by prefix, suffix and substring:
SELECT email FROM users WHERE email LIKE 'a%'; -- starts with a
SELECT email FROM users WHERE email LIKE '%@gmail.com'; -- ends with @gmail.com
SELECT email FROM users WHERE email LIKE '%admin%'; -- contains adminAll lessons in this course
- LIKE Patterns and Wildcards
- IN and NOT IN for Sets
- BETWEEN for Ranges
- IS NULL, IS NOT NULL and COALESCE