I had the same requirement, and I was looking for a mechanism that would match as REGEXP "A|B|C" , which means matching A , B , C
So finally, this is the solution I came across:
WITH words(str, strSubString, hasComma) AS ( VALUES ('', "foo,bar", 1) UNION ALL SELECT SUBSTR(strSubString, 0, CASE WHEN INSTR(strSubString, ',') THEN INSTR(strSubString, ',') ELSE LENGTH(strSubString) + 1 END), LTRIM(SUBSTR(strSubString, INSTR(strSubString, ',')), ','), INSTR(strSubString, ',') FROM ssgPaths WHERE hasComma ) SELECT p.* FROM p_extra_fields as x INNER JOIN products as p ON x.product = p.id JOIN words AS w ON x.value LIKE '%' || w.str || '%' AND w.str != '' WHERE x.type = "1" and x.key in ('model', 'color', 'make');
Matching criteria are equivalent to @Gordon's query:
WHERE x.type = "1" and x.key in ('model', 'color', 'make') and (x.value like '%foo%' or x.value like '%bar%')
But this gives you the flexibility to map values โโdynamically depending on your query parameter (you can extract "foo,bar" for the parameter).
For example, without changing the query, you can go through "foo,bar,boo" and match the regular expressions: "foo|bar|boo"