Is there a combination of "LIKE" and "IN" in SQL?

76    Asked by kivoma_9873 in SQL Server , Asked on Sep 1, 2025

How can you combine LIKE and IN in SQL to filter multiple patterns at once?  Learn what techniques exist, how they work, and the best ways to achieve flexible search queries.

In SQL, there isn’t a direct operator that combines LIKE and IN together, but you can achieve the same functionality by using them in creative ways. Essentially, the idea is to filter rows where a column matches any of several patterns.

Here are some common approaches:

Multiple LIKE conditions with OR:

 You can chain multiple LIKE statements together.

 SELECT * 
FROM Employees
WHERE Name LIKE 'John%'
   OR Name LIKE 'Mike%'
   OR Name LIKE 'Sara%';

 This works, but can get lengthy with many conditions.

Using IN with wildcards (not directly supported):

 Unfortunately, IN does not work with wildcards. For example:

   WHERE Name IN ('%John%', '%Mike%')  -- ❌ Invalid

 This won’t behave like LIKE.

Alternative using regular expressions (if supported):

 Some databases (like MySQL with REGEXP or PostgreSQL with SIMILAR TO) allow you to use a single condition to match multiple patterns.

 SELECT * 
FROM Employees
WHERE Name REGEXP '^(John|Mike|Sara)';

Dynamic SQL for flexibility:

  •  In more complex cases, you can build dynamic SQL queries where multiple patterns are constructed programmatically.
  •  Best Practice: Use multiple LIKE conditions with OR when working in standard SQL. If your database supports regex (REGEXP or SIMILAR TO), it’s a cleaner and more efficient approach for multiple patterns.
  • In short, while there isn’t a built-in LIKE IN syntax, you can achieve the same outcome with either multiple LIKE clauses or database-specific regex solutions.



Your Answer

Interviews

Parent Categories