Categories: MySQL FunctionsPHP

MySQL8 MAKE_SET() Functions – String Functions

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.


MySQL MAKE_SET() Functions: Syntax

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

MySQL MAKE_SET() Functions: Parameter

[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]


MySQL MAKE_SET() Functions: Available from

[table caption=”” width=”100%” colwidth=”25%|75%” colalign=”left|left”]
Version, MySQL 5.7
[/table]


MAKE_SET() Example 1 : Basic Usage

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.

  1. 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.
  2. The second bit starting from the right of the binary number shown is 1 (or on), so the second string starting from the right of the list of strings is put into the set.
  3. The third bit starting from the right of the binary number shown is 0 (or off), so the third string starting from the right of the list of strings is not put into the set.
  4. The fourth bit counting from the right is 1, so the fourth string of the list of strings is added to the set.

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.


MAKE_SET() Example 2 : Some more examples

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)

LOCATE() Example 3 : Multiple Binary Values

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)


LIKE() Example 4 : NULL arguments

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.


Related articles : HEX(), CONCAT(), CONCAT_WS() , LOWER(), LTRIM(), INSTR(), POSITION().


PHP Related articles : SUBSTR(), SUBSTR_COUNT(), SUBSTR_COMPARE(), SUBSTR_REPLACE(), PHP STRING FUNCTIONS().

jyoti rani

Recent Posts

Modern Toys, Magical Moments: Why the Best Toy Shop in Noida Is More Than Just a Store

When it comes to children, there’s one universal truth: the right toy can spark imagination, build skills, and make memories…

6 months ago

Rediscovering Joy: A New Era of Creativity & Comfort in Toy Stores

In today’s digital age, where screens and gadgets dominate our children’s lives, there’s something heartwarming about a well-loved plush toy…

6 months ago

Unboxing Imagination: Discovering the Joy of Play at a Toy Store in Noida

In a world dominated by screens and fast-paced routines, it’s easy to forget the simple magic of a toy in…

6 months ago

Imagination Unboxed: Discover Joy at the Toy Shop in Delhi

In the heart of Delhi’s vibrant streets lies a world where imagination meets innovation — the magical universe of toys.…

6 months ago

Play with Purpose: Discovering the Ultimate Toy Store in Noida

When was the last time a toy truly amazed you—not just as a product, but as a thoughtful tool for…

6 months ago

From Tears to Toys: Exploring Modern Childhood through Delhi’s Favorite Toy Shop

In the digital age, the way we experience childhood has changed, but the essence remains the same—imagination, exploration, and joy.…

6 months ago