Home >Database >Mysql Tutorial >How to set comma separated list to table in MySQL?
You can use UNION ALL to achieve this.
Let us use UNION ALL to make the list 10, 20, 30, 40, 50 as a table -
mysql> select 10 Number UNION ALL select 20 Number UNION ALL select 30 Number UNION ALL select 40 Number UNION ALL select 50 Number;
+--------+ | Number | +--------+ | 10 | | 20 | | 30 | | 40 | | 50 | +--------+ 5 rows in set (0.00 sec)
Let us see another example. To get list 1,2,3 as table, use following query -
mysql> SELECT 1 a UNION ALL SELECT 2 a UNION ALL SELECT 3 a;
+---+ | a | +---+ | 1 | | 2 | | 3 | +---+ 3 rows in set (0.00 sec)
The above is the detailed content of How to set comma separated list to table in MySQL?. For more information, please follow other related articles on the PHP Chinese website!