(I am posting this in the PHP category because I needed it when developing a webapp, maybe others benefit from it as well)
Basically I wanted to store multiple values in a single field to avoid additional tables with table links and unnecessary complexity in my already-2-screen-long queries.
I needed to store the 5 possible values A B C D E in this field (and 20 values in another case) then compare the fields with each other in the WHERE clause of the queries. If you start thinking about this, it isn't common sense at all because neither LIKE or = works here.
To make it more clear, we are talking about values like ABC, BCDE, ADE, BE, CDE etc and we need to tell if any of the characters are identical in two strings. For example:
somefunc('AB', 'AB') = true
somefunc('AB', 'BCD') = true
somefunc('ABE', 'CD') = false
somefunc('ABCDE', 'E') = true
The first thing came to mind was to create this function but it wasn't possible in my case.
I was about to create those additional tables and add another couple of lines to my queries when I realized that the SET datatype can help. I was in heaven when I found the FIND_IN_SET() function. It isn't enough though. FIND_IN_SET() allows you to compare a single value to a list of values (e.g. 'A', 'ABC'). I need to compare list of values to list of values ('ABC', 'CDE').
Here comes the fact that values with the SET datatype are stored as binary and can be used as integers.
Finally the solution:
SELECT * FROM tt
WHERE field_a & field_b
This is the most elegant solution I can come up with. It also decreases the development time from 1 days to 1 hour.
There is a limitation though, from the MySQL manual: "A SET can have a maximum of 64 different members."
Hope this helps somebody. Happy coding!