
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
Set a Comma-Separated List as a Table in MySQL
You can use UNION ALL for this.
Let us get list 10, 20, 30, 40, 50 as a table with UNION ALL −
mysql> select 10 Number UNION ALL select 20 Number UNION ALL select 30 Number UNION ALL select 40 Number UNION ALL select 50 Number;
Output
+--------+ | Number | +--------+ | 10 | | 20 | | 30 | | 40 | | 50 | +--------+ 5 rows in set (0.00 sec)
Let us see another example. To get the list 1,2,3 as a table, use the below query −
mysql> SELECT 1 a UNION ALL SELECT 2 a UNION ALL SELECT 3 a;
Output
+---+ | a | +---+ | 1 | | 2 | | 3 | +---+ 3 rows in set (0.00 sec)
Advertisements