How can I return the values of columns from MySQL table as a set of values?


With the help of MySQL MAKE_SET() function, we can return the values of columns from MySQL table as a set of values. To understand it, we are taking the example of Student_Name table which has the following data −

mysql> Select * from Student_Name;
+---------+-------+---------+
| FName   | Mname | Lname   |
+---------+-------+---------+
| Rahul   | NULL  | Singh   |
| Gaurav  | Kumar | NULL    |
| Harshit | NULL  | Khurana |
| Yash    | Pal   | Sharma  |
+---------+-------+---------+
4 rows in set (0.00 sec)

Now, suppose if we want to make the set of ‘Fname’ and ‘Lname’ column’s values then the following query will do it −

mysql> Select MAKE_SET(1|4,fname,mname,lname)AS '(Fname,Lname)' from Student_name;
+-----------------+
| (Fname,Lname)   |
+-----------------+
| Rahul,Singh     |
| Gaurav          |
| Harshit,Khurana |
| Yash,Sharma     |
+-----------------+
4 rows in set (0.00 sec)

Updated on: 22-Jun-2020

149 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements