There is a field in the table that stores the id product categories, separated by a comma (do not ask why ... this, alas, cannot be changed - and it’s too late, the base is huge).
Type of such:
productID categories --------- ------------ 13730 101,103 15336 101,109 15320 103,104 15310 104,105 1314 19,20 348 19,26 1309 20,21 4521 21,25 3739 29,68 4019 32,69 In php there is an array (for example) $categories = Array(20, 21, 101, 103); .
Task : it is necessary to find all the goods that have at least one category from the given array.
You can iterate over all the elements of the array one at a time, something like
WHERE (FIND_IN_SET(20, table.categories)>0 OR FIND_IN_SET(21, table.categories)>0 OR FIND_IN_SET(101, table.categories)>0 OR FIND_IN_SET(103, table.categories)>0) But, I'm afraid, with a large array (and this may well happen), the request will be long: after all, text processing is going on, not by whole numbers, as we would like ...
Does anyone have any other options?