MAKE_SET() Functions returns a comma-separated list of values that match with bits of a base 10 number converted to its binary equivalent.
When we call the function, we specify any number of strings (separated by a comma), as well as one or more bit values that determine which strings to return in the set value.
string1 corresponds to bit 0, string2 to bit 1, and so on.
NULL values in str1, str2, .. are not appended to the result. See example 4.
[table caption=”” width=”100%” colwidth=”15%|15%|15%|55%” colalign=”left|left|left|left”]
Name, Required /Optional,Type, Description
string, Required, String , It represents any number of strings separated by a comma.
bits, Required, String , It represents one or more bit values that determine which strings to return in the set value.
[/table]
[table caption=”” width=”100%” colwidth=”25%|75%” colalign=”left|left”]
Version, MySQL 5.7
[/table]
Below is the example to show it. Here we have comma-separated list of values and bit values that determine which strings to return in the set value.
mysql> SELECT BIN(11) AS 'Binary 11',MAKE_SET(11, 'A','B','C','D'); +-----------+-------------------------------+ | Binary 11 | MAKE_SET(11, 'A','B','C','D') | +-----------+-------------------------------+ | 1011 | A,B,D | +-----------+-------------------------------+ 1 row in set (0.00 sec))
Note : that the binary equivalent of 11 is 1011.
Example 2 :
mysql> SELECT BIN(7) AS 'Binary 1',MAKE_SET(7, 'A','B','C','D'); +----------+------------------------------+ | Binary 1 | MAKE_SET(7, 'A','B','C','D') | +----------+------------------------------+ | 111 | A,B,C | +----------+------------------------------+ 1 row in set (0.00 sec)
Note : The binary equivalent of 7 is 111. 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 also 1, so the second and third strings (i.e., B and C) are added to the set.
Below are the example to show some more examples.
mysql> SELECT BIN(4) AS 'Binary 4',MAKE_SET(4, 'A','B','C','D'); +----------+------------------------------+ | Binary 4 | MAKE_SET(4, 'A','B','C','D') | +----------+------------------------------+ | 100 | C | +----------+------------------------------+ 1 row in set (0.00 sec) mysql> SELECT BIN(8) AS 'Binary 8',MAKE_SET(1000, 'A','B','C','D'); +----------+---------------------------------+ | Binary 8 | MAKE_SET(1000, 'A','B','C','D') | +----------+---------------------------------+ | 1000 | D | +----------+---------------------------------+ 1 row in set (0.00 sec)
You can use a pipe in order to pass multiple binary values in the first argument:
mysql> SELECT BIN(4|2),MAKE_SET( 4 | 2 , 'A','B','C','D'); +----------+------------------------------------+ | BIN(4|2) | MAKE_SET( 4 | 2 , 'A','B','C','D') | +----------+------------------------------------+ | 110 | B,C | +----------+------------------------------------+ 1 row in set (0.00 sec)
Note that you’ll get the same result if you reverse the binary values in the first argument:
mysql> SELECT BIN(2|4),MAKE_SET( 2 | 4 , 'A','B','C','D'); +----------+------------------------------------+ | BIN(2|4) | MAKE_SET( 2 | 4 , 'A','B','C','D') | +----------+------------------------------------+ | 110 | B,C | +----------+------------------------------------+ 1 row in set (0.00 sec)
Any strings with NULL values are not appended to the result. See below example
mysql> SELECT BIN(2|4),MAKE_SET( 2 | 4 , 'A',NULL,'C','D'); +----------+-------------------------------------+ | BIN(2|4) | MAKE_SET( 2 | 4 , 'A',NULL,'C','D') | +----------+-------------------------------------+ | 110 | C | +----------+-------------------------------------+ 1 row in set (0.05 sec)
See all MySQL String functions MySQL 8 String Functions.
When it comes to children, there’s one universal truth: the right toy can spark imagination, build skills, and make memories…
In today’s digital age, where screens and gadgets dominate our children’s lives, there’s something heartwarming about a well-loved plush toy…
In a world dominated by screens and fast-paced routines, it’s easy to forget the simple magic of a toy in…
In the heart of Delhi’s vibrant streets lies a world where imagination meets innovation — the magical universe of toys.…
When was the last time a toy truly amazed you—not just as a product, but as a thoughtful tool for…
In the digital age, the way we experience childhood has changed, but the essence remains the same—imagination, exploration, and joy.…