I have a say, ITEM table in MySQL that stores data as follows:
ID FEATURES -------------------- 1 AB,CD,EF,XY 2 PQ,AC,A3,B3 3 AB,CDE 4 AB1,BC3 --------------------
As input, I get a CSV string, something like "AB, PQ". I want to get records containing AB or PQ. I realized that for this we have to write a MySQL function. So, if we have this magic function MATCH_ANY defined in MySQL that does this, I would simply execute SQL as follows:
select * from ITEM where MATCH_ANY(FEAURES, "AB,PQ") = 0
The above query will return records 1, 2 and 3.
But I am doing all kinds of problems when implementing this function, because I realized that MySQL does not support arrays and there is no easy way to split the lines based on the separator.
Remodeling a table is the last option for me, as it has many problems.
I can also execute queries containing several MATCH_ANY functions, such as:
select * from ITEM where MATCH_ANY(FEATURES, "AB,PQ") = 0 and MATCH_ANY(FEATURES, "CDE")
In the above case, we get the intersection of records (1, 2, 3) and (3), which will be only 3.
Any help is greatly appreciated.
thanks