Alex Rivera | Logout

Using SQL LIKE and IN together

Asked 2010-02-23T12:42:19.823
61

Is there a way to use LIKE and IN together?

I want to achieve something like this.

SELECT * FROM tablename WHERE column IN ('M510%', 'M615%', 'M515%', 'M612%');

So basically I want to be able to match the column with a bunch of different strings. Is there another way to do this with one query or will I have to loop over the array of strings I am looking for?

Edit
Report

2 Answers

10

You'll need to use multiple LIKE terms, joined by OR.

answered 2010-02-23T12:44:56.933
2
substr([column name],
       [desired starting position (numeric)],
       [# characters to include (numeric)]) in ([complete as usual])

Example

substr([column name],1,4) in ('M510','M615', 'M515', 'M612')
answered 2012-11-27T22:47:01.940

Your Answer