借助MySQL的MAKE_SET()函数,我们可以将MySQL表中的列值作为一组值返回。为了理解它,我们以Student_Name表为例,其中包含以下数据−
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)
现在,假设我们想要创建“Fname”和“Lname”列的值集合,那么以下查询将实现:
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)