0

I know I can search if an array contains a column value like this

SELECT * FROM table WHERE column IN (".implode(',', $array).");

And I can also check if a value or variable exist in a column set

SELECT * FROM table WHERE FIND_IN_SET('".$value."', column);

But now I want to check if any of the element in my array is also in my set of column, maybe something like

SELECT * FROM table WHERE ANY_OF_ELEMENTS_IN(".implode(',', $array).") IS IN (column)
KANAYO AUGUSTIN UG
  • 2,078
  • 3
  • 17
  • 31
  • It's not possible. You need to make `IN` over all possible columns (or edit your app logic to know in which column(s) you're looking). – pavel Nov 21 '21 at 20:34
  • This is one of many troubles you will have if you store lists as a string of comma-separated values. I recommend avoiding that. Store a list as multiple rows, with one value per row. Use SQL predicates as operations on sets of rows, not pattern-matching against comma-separated lists. Then many types of queries become a lot easier. – Bill Karwin Nov 21 '21 at 20:42

0 Answers0