With the help of MySQL's MAKE_SET() function, we can return the column values in the MySQL table as a set of values. To understand it, let’s take the Student_Name table as an example, which contains 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, assuming we want to create a collection of values for the “Fname” and “Lname” columns, then the following query will be achieved:
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)
The above is the detailed content of How to return column values from a MySQL table as a set of values?. For more information, please follow other related articles on the PHP Chinese website!