trilisser
trilisser

Reputation: 381

how to select a column with more than one values from non-existing table

How to select more than one value from a 'non-existing' table.

For example:

SELECT ('val1', 'val2') as "test"

enter image description here

How to make a column "test" with two values/rows val1 and val2?

Upvotes: 0

Views: 68

Answers (3)

hc_dev
hc_dev

Reputation: 9377

To temporarily generate rows with values, PostgreSQL has following options:

  1. VALUES Lists like VALUES (1, 'one'), (2, 'two'), (3, 'three');
  2. WITH Queries (Common Table Expressions) common-table-expression
  3. CREATE TABLE TEMPORARY to create a table for temporary use in this session

For small numbers of rows I would suggest the VALUES expression. For more rows and usage in complex queries I would suggest the temporary table.

See also:

Upvotes: 1

If you use SQL Server family, you can use a query similar to this :

declare @tmpTable as table (test varchar(50))


insert into @tmpTable
select 'val' Go 100

now you can use @tmpTable

Upvotes: 0

miemengniao
miemengniao

Reputation: 722

you can use union two rows in table like below code:

select 'val1' as "test"
union
select 'val2' as "test"

enter image description here

Upvotes: 1

Related Questions