MAKE_SET( )

This MySQL function converts the decimal number in bits to binary and returns a comma-separated list of values for all the bits that are set in that number, using string1 for the low-order bit, string2 for the next lowest bit, etc.

Syntax

Below is the syntax for this command. Text within square brackets (i.e, [ and ] ) are optional. Choices are separated by bars (i.e, | ). Ellipses preceded by a comma indicates a repeating pattern. Ellipses before or after syntax are used to highlight a relevant except from the larger syntax. Text displayed in italic letters represent text that should be replaced with the specific names related to the database (e.g., column with the name of the column).

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

Explanation

This function converts the decimal number in bits to binary and returns a comma-separated list of values for all the bits tha re set in that number, using string1 for the low-order bit, string2 for the next lowest bit, etc.

Examples

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

+----------+------+
| Binary 9 | Set  |
+----------+------+
| 1001     | A,D  |
+----------+------+

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 in the list is put into the results. The second and third bits of the binary number are 0, so the second and third strings ('B' and 'C') are left out of the results. The fourth bit counting from the right is 1, so the fourth string of the list is added to the results.