8

Possible Duplicate:
Can you define “literal” tables in SQL?

Occasionally I find myself in a situation where I'd like to join an existing table to a table of values that are entered in the query. Something like:

SELECT ((1,2,3),(4,5,6)); 

Where the query would return two rows of 3 columns. Obviously this syntax is not correct, but it is possible to generate a single row of data in this way. For example:

SELECT 1,2,3;

Is there actually a way to do what I'm trying to achieve?

0

1 Answer 1

11
SELECT 1,2,3
UNION ALL
SELECT 4,5,6;
Sign up to request clarification or add additional context in comments.

3 Comments

Brilliant, thanks. I was hoping it would be more elegant but it works! I can use it combination with this stackoverflow.com/questions/1764881/… to generate histogram data without needing to create an extra table.
is there a way to name the columns in this, without specifying the same "AS column1"... in each line?
yes just give names to the first select : select 2 as id, 3 as code union all select 1, 4

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.