Jun 13, 2017

MySQL MAKE_SET() returns a set value consisting of the strings that have the corresponding bit in the first argument.

MySQL MAKE_SET() returns a set value (a string containing substrings separated by “,” characters) consisting of the strings that have the corresponding bit in the first argument.
mysql> SELECT MAKE_SET(1 | 4,'hello','nice','world'); 
+----------------------------------------+
| MAKE_SET(1 | 4,'hello','programming','world') |
+----------------------------------------+
| hello,world                            | 
+----------------------------------------+
1 row in set (0.00 sec)


If the first argument (1 | 4) is converted to binary, it returns 1 or 100. For 1, the rightmost bit is 1, so the function returns 'hello'. For 100, the rightmost bit is 0, so the function returns nothing for the rightmost bit (0). But the function returns 'world' for the leftmost bit (1). So, the final output is hello,world.