1

i want to find the rows that have at least i item in an array in common with my query array.

this is close to what i want:

SELECT *
    FROM Table
    WHERE column IN (1, 2, 3)

column contains data from an array stored as a string. for example:
i am looking for any row that has a 1,2 or 3 in it.

row 1.column = 1  
row 2.column = 3,6,7  
row 3.column = 8,9,10,11

i would like row 1 and row 2, but not row 3.

or, would it be better to store each item of array as a separate row?

greg
  • 15
  • 3

1 Answers1

1

It would almost definitely be better to store as separate rows (see Is storing a delimited list in a database column really that bad?). If you do use a single column, you can query it using FIND_IN_SET():

SELECT *
  FROM `table`
 WHERE FIND_IN_SET(1, `column`)
    OR FIND_IN_SET(2, `column`)
    OR FIND_IN_SET(3, `column`);
Community
  • 1
  • 1
shmosel
  • 49,289
  • 6
  • 73
  • 138