0

In SQL statement in MySql it is easy to create a row of values on fly by using somethig like

SELECT 1, 2, 3, 4, 5, 6, 7, 8, 9, 10;

this will generate a single row containing numbers from 1 to 10 but is it possible to have a single column that contains these values.

Polla A. Fattah
  • 801
  • 2
  • 11
  • 32

1 Answers1

2

A simple way is a recursive CTE:

with recursive cte as (
      select 1 as n
      union all
      select n + 1
      from cte
      where n < 10
     )
select cte.*
from cte;

If you have a handful of values, you can also just create them using union all:

select *
from (select 1 as n union all select 2) n
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786