How to SELECT using both wildcards (LIKE) and array (IN)?

Dave picture Dave · Dec 15, 2011 · Viewed 41.7k times · Source

In SQL, if you want to perform a SELECT with a wildcard, you'd use:

SELECT * FROM table_name WHERE field_name LIKE '%value%'

If you wanted to use an array of possible values, you'd use:

SELECT * FROM table_name WHERE field_name IN ('one', 'two', 'three')

But, what would you do if you wanted to use both wildcards AND an array?

Kind of like:

SELECT * FROM table_name WHERE field_name LIKE IN ('%one', '_two', 'three[abv]')

Answer

LaGrandMere picture LaGrandMere · Dec 15, 2011
SELECT *
FROM table_name
WHERE field_name LIKE '%one'
   OR field_name LIKE '_two'
   OR field_name LIKE 'three[abv]'