Home > Database > Mysql Tutorial > How to return column values ​​from a MySQL table as a set of values?

How to return column values ​​from a MySQL table as a set of values?

WBOY
Release: 2023-09-15 08:01:07
forward
794 people have browsed it

如何将 MySQL 表中的列值作为一组值返回?

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)
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template