Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

sql

sql-like

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]')
like image 883
Dave Avatar asked Dec 15 '11 12:12

Dave


1 Answers

SELECT *
FROM table_name
WHERE field_name LIKE '%one'
   OR field_name LIKE '_two'
   OR field_name LIKE 'three[abv]'
like image 99
LaGrandMere Avatar answered Oct 13 '22 00:10

LaGrandMere