TOP CATEGORIES

×

How to use multiple LIKE in SQL?

N

Nidhee

In SQL (Structured Query Language), the LIKE operator is used to find a specific pattern in a column. When you want to search for multiple patterns in the same query, you can combine different LIKE conditions. This is especially useful for filtering data based on partial matches in text fields such as names, descriptions, or emails.

What is the LIKE Operator in SQL?

The LIKE operator allows you to match patterns using wildcard characters:

  • % represents zero or more characters
  • _ represents a single character

For Example

SELECT * FROM users WHERE name LIKE 'A%';

This query returns all users whose names start with the letter "A".

How to Use Multiple LIKE in SQL

To search for multiple patterns, combine several LIKE clauses using the OR operator.

Basic Syntax:

SELECT * FROM table_name

WHERE column_name LIKE 'pattern1'

OR column_name LIKE 'pattern2'

OR column_name LIKE 'pattern3';

SELECT * FROM products

WHERE product_name LIKE '%Phone%'

OR product_name LIKE '%Laptop%'

OR product_name LIKE '%Tablet%';

This returns all products that include the words "Phone", "Laptop", or "Tablet" in their names.

Using Multiple LIKE with AND (Advanced Use)

Sometimes, you may want to match multiple patterns that must all exist within the same field. Use AND in that case:

SELECT * FROM articles

WHERE content LIKE '%Technology%'

AND content LIKE '%Innovation%';

0 votes

Your Answer