MySQL MAKE_SET Function

MySQL MAKE_SET function is one of the MySQL String Functions, which returns a set value that contains substrings separated by a comma character. This MAKE_SET function uses bits to form or make set values.

Let me show you how to write MySQL String MAKE_SET Function query to make or create a set value using binary bits or bit values with an example.

MySQL MAKE_SET Syntax

The basic syntax of MAKE_SET of a string in MySQL is as shown below:

MAKE_SET(bits, Str1, Str2,...StrnN)

MySQL MAKE_SET Example

The MySQL string MAKE_SET function makes a set using the bit values of substrings. The following query shows multiple ways to use this MAKE_SET function. Here, bits = 1 = 0001. So, 1 = a, 0 = b, 0 = c, 0 = d. It means, output is a. Within the third statement, bits = 2 = 0010 (0 = a, 1 = b, 0 = c, 0 = d). So, it returns b

SELECT MAKE_SET(0, 'a', 'b', 'c', 'd');

SELECT MAKE_SET(1, 'a', 'b', 'c', 'd');

SELECT MAKE_SET(2, 'a', 'b', 'c', 'd');
MySQL MAKE_SET Function 1

In this MySQL Make_Set example, we are using the multiple bit values. First, 1|3, bits 1 = 00001 means, 1= hi, 0 = hello, 0 = mysql, 0 = world, 0 = Welcome. Next, 3 = 00011. So, the String Function output will be hi, hello.

Within the third MySQL statement, we used 2|4. bits 2 = 00010 => hello. bits 4 = 00100 => 0= hi, 0 = hello, 1 = mysql, 0 = world, 0 = Welcome. It means, hello, mysql

SELECT MAKE_SET(1 | 3, 'hi', 'hello', 'mysql', 'world', 'welcome');

SELECT MAKE_SET(1 | 4, 'hi', 'hello', 'mysql', 'world', 'welcome');

SELECT MAKE_SET(2 | 4, 'hi', 'hello', 'mysql', 'world', 'welcome');
MySQL MAKE_SET Function 2