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

MySQLMySQLi Database

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)
raja
Published on 21-Feb-2018 11:31:41
Advertisements