Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL: Select from coma separated list / list as table? "SELECT a FROM (1, 2, 3)"

Tags:

sql

select

mysql

Is it possible to do something like this (obviously this syntax does not work):

SELECT a FROM (1, 2, 3)

to get this:

| a |
+---+
| 1 |
| 2 |
| 3 |

?

That is I want to make rows from coma separated list, without using any table, or at least without creating table in db (maybe this is possible using something like temporary table?).

Maybe it is possible to get column of given values without using select, that is using some other sql statment? If it is not possible in MySQL, but possible in some other SQL it still would be interesting to know.

like image 313
morphles Avatar asked Nov 15 '12 10:11

morphles


People also ask

How do I select comma separated values in MySQL?

In MySQL, you can return your query results as a comma separated list by using the GROUP_CONCAT() function. The GROUP_CONCAT() function was built specifically for the purpose of concatenating a query's result set into a list separated by either a comma, or a delimiter of your choice.

How do you select comma separated values in SQL?

How do I get comma separated values in SQL Server? In order to fetch the comma separated (delimited) values from the Stored Procedure, you need to make use of a variable with data type and size same as the Output parameter and pass it as Output parameter using OUTPUT keyword.

How can I get multiple row values in comma separated in MySQL?

How can I get multiple row values in comma separated in MySQL? MySQL. MySQL has the GROUP_CONCAT() function that allows us to output our query results in a comma separated list: SELECT GROUP_CONCAT(PetName) FROM Pets; Oracle Database.


1 Answers

SELECT 1 a UNION ALL SELECT 2 a UNION ALL SELECT 3 a;
like image 123
aykut Avatar answered Oct 06 '22 00:10

aykut