Name

MAKE_SET( )

Synopsis

MAKE_SET(bits, string1, string2, ...)

This function returns a comma-separated list of values that coincide with bits of a base 10 number converted to its binary equivalent.

SELECT BIN(9) AS 'Binary 9',
       MAKE_SET(100, 'A','B','C','D')
          AS Set;
+----------+------+
| Binary 9 | Set  |
+----------+------+
| 1001     | A,D  |
+----------+------+

Notice that the binary equivalent of 9 is 1001. The first bit starting from the right of the binary number shown is 1 (or on), so the first string starting from the right of the list of strings is put into the set. The second and third bits of the binary number are 0, so the second and third strings (i.e., B and C) are not added to the set. The fourth bit counting from the right is 1, so the fourth string of the list of strings is added to the set.

Get MySQL in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.