9

Is there a way to perform a select and return a static list? Something like the following:

select * from ('CA', 'FB', 'FC')

It should return

CA
FB
FC
GMB
  • 216,147
  • 25
  • 84
  • 135
Bill
  • 915
  • 2
  • 13
  • 23

2 Answers2

27

If you want each value on a separate row, you can use table constructor values():

select val
from (values ('CA'), ('FB'), ('FC')) as t(val)

If you wanted more columns, you would use tuples rather than singletons:

select val1, val2
from (values 
    ('CA', 'CB'), 
    ('FA', 'FB'),
    ('FC', 'FD') 
) as t(val1, val2)
Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
GMB
  • 216,147
  • 25
  • 84
  • 135
  • If you want a multi-column table, you can also use this syntax (at least in Postgresql): SELECT col1, colA FROM (VALUES ('hello', 'world'), ('run', 'scream')) AS t(col1, colA) – Sarah Messer May 24 '22 at 15:14
2

Perhaps:

select 'CA'
union all
select 'FB'
union all
select 'FC'
avery_larry
  • 2,069
  • 1
  • 5
  • 17