Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Select to return a static list of values?

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
like image 935
Bill Avatar asked Feb 01 '26 05:02

Bill


2 Answers

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)
like image 66
GMB Avatar answered Feb 03 '26 23:02

GMB


Perhaps:

select 'CA'
union all
select 'FB'
union all
select 'FC'
like image 40
avery_larry Avatar answered Feb 03 '26 22:02

avery_larry



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!