2.3 — Text Search with LIKE
What You'll Learn
- How to filter text using patterns in SQL
- The
LIKE
operator and wildcards - Excel’s "contains" filter equivalent
Filtering Text in Excel vs. SQL
Excel:
Use the filter to show rows where "Product" contains "App".
SQL:
sql
SELECT * FROM sales
WHERE Product LIKE '%App%';
%
is a wildcard: it matches any number of characters.'App'
can be anywhere in the text.
More Examples
Starts with "App":
sqlWHERE Product LIKE 'App%'
Ends with "es":
sqlWHERE Product LIKE '%es'
Exact match:
sqlWHERE Product = 'Apples'
Case Sensitivity
Some databases are case-sensitive, others are not.
To ensure case-insensitive search, you can use
LOWER()
:sqlWHERE LOWER(Product) LIKE '%app%'
Key Points
- Use
LIKE
and%
for flexible text filtering. - This is similar to Excel’s "contains", "begins with", or "ends with" filters.
Next Steps
Next, you'll learn how to combine multiple filter conditions for advanced filtering.