How to select more than one value from a ‘non-existing’ table.
For example:
SELECT ('val1', 'val2') as "test"
How to make a column "test" with two values/rows val1 and val2?
3
you can use union two rows in table like below code:
union
select 'val1' as "test" union select 'val2' as "test"
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
To temporarily generate rows with values, PostgreSQL has following options:
VALUES
VALUES (1, 'one'), (2, 'two'), (3, 'three');
WITH
CREATE TABLE TEMPORARY
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:
Click here to cancel reply.
3
Answers
you can use
union
two rows in table like below code:If you use SQL Server family, you can use a query similar to this :
now you can use @tmpTable
To temporarily generate rows with values, PostgreSQL has following options:
VALUES
Lists likeVALUES (1, 'one'), (2, 'two'), (3, 'three');
WITH
Queries (Common Table Expressions) common-table-expressionCREATE TABLE TEMPORARY
to create a table for temporary use in this sessionFor 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: