
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Return Column Values from MySQL Table as a Set
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)
Advertisements