- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to 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;
+--------+ | 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;
+---+ | a | +---+ | 1 | | 2 | | 3 | +---+ 3 rows in set (0.00 sec)
- Display MySQL Results as comma separated list?
- Display duplicate record as a distinct value with corresponding values as distinct comma separated list in MySQL?
- How can I match a comma separated list against a value in MySQL?
- Check if value exists in a comma separated list in MySQL?
- How can I search within a table of comma-separated values in MySQL?
- Searching from a comma separated MySQL column?
- Regex to find string and next character in a comma separated list - MySQL?
- Convert a Set of String to a comma separated String in Java
- MySQL query to retrieve records from the part of a comma-separated list?
- Convert a List of String to a comma separated String in Java
- How to use a comma-separated string in an `IN ()` in MySQL?
- How to display data from a MySQL column separated by comma?
- How to create a comma separated string from a list of string in C#?
- How would you make a comma-separated string from a list in Python?
- How to sum a comma separated string (string with numbers) in MySQL?