Reputation: 387
I'm trying to check if an array of numbers has these numbers inside another array in MySQL using where like
Example (SQL Fiddle):
My table:
id | columnNumbers |
---|---|
1 | 2,41 |
2 | 1,21,35 |
3 | 5,10,55 |
const numbers = [1, 41]
db.query(`select * from table where concat(",", columnNumbers, ",") like ${numbers.map(n => `"%,${n},%"`).join(' or ')}`)
Output:
id | columnNumbers |
---|---|
2 | 1,21,35 |
Expected output:
id | columnNumbers |
---|---|
1 | 2,41 |
2 | 1,21,35 |
MySQL version:
Upvotes: 1
Views: 37
Reputation: 42728
select *
from _table
where FIND_IN_SET(1, columnNumbers)
or FIND_IN_SET(41, columnNumbers)
Upvotes: 1