Question on the Libera/#mysql IRC channel:
Is there a way to split a simple select into multiple returned
rows? For example, select 1, 2, 3 to be returned as
rows?
This is actually asking for a table literal notation. I know of four ways to construct a table literal in MySQL:
The oldest way to construct a table literal in any SQL that
supports UNION is the UNION ALL
construct. Write SELECT statements to return literal
rows, and add them together to a table using UNION
ALL:
mysql> select i from (
-> select 1 as i union all
-> select 2 as i union all
-> select 3 as i
-> ) as t;
+---+
| i |
+---+
| 1 |
| 2 |
| 3 |
+---+
3 rows in set (0.00 sec)
This has always worked, even on the oldest versions …
[Read more]