mysql select trim explode
Используются функции trim
и substring_index
. Пример — нужно получить id
которые хранятся в формате '82','84','87'
:
SELECT * FROM `filters_vars` WHERE `shown`=1 AND `filter`=37 AND `id` IN (SELECT TRIM(BOTH "'" FROM (substring_index(`value`,",",1))) AS `values` FROM `filter_values` WHERE `value`!="" AND `filter`=37 AND `item` IN (SELECT `id` FROM `catalog` WHERE `shown`=1 AND (`parent`=76 OR `id` IN (SELECT `item` FROM `catalog_dub` WHERE `razdel`=76))) GROUP BY `values`) ORDER BY 'pos';
SELECT * FROM `filters_vars` WHERE `shown`=1 AND `filter`=37 AND `id` IN ( SELECT TRIM(BOTH "'" FROM (SUBSTRING_INDEX(`value`,",",1))) AS `values` FROM `filter_values` WHERE `value`!="" AND `filter`=37 AND `item` IN ( SELECT `id` FROM `catalog` WHERE `shown`=1 AND (`parent`=76 OR `id` IN (SELECT `item` FROM `catalog_dub` WHERE `razdel`=76)) ) GROUP BY `values` ) ORDER BY 'pos';