Mohammad Masoudian
Mohammad Masoudian

Reputation: 3501

MySQL FIND_IN_SET(array1, array2)

Is it possible to search for an array of numbers in a comma separated column?

I know that this is possible

SELECT * FROM products WHERE FIND_IN_SET('1', '1,3,5') > 0

But is this possible too?

SELECT * FROM products WHERE FIND_IN_SET('1,2', '1,3,5') > 0

If 1 or 2 be in the column it should return > 0

if you know another method just let me know

thank you

Upvotes: 1

Views: 201

Answers (1)

juergen d
juergen d

Reputation: 204884

No, but you can use find_in_set multiple times

SELECT * FROM products
WHERE FIND_IN_SET(1, '1,3,5') > 0
   OR FIND_IN_SET(2, '1,3,5') > 0

Upvotes: 2

Related Questions