phadaphunk
phadaphunk

Reputation: 13273

Select multiple rows with alias

I don't know how to search for this beause I don't know how this type of select is called.
If I do my select like this :

SELECT 1, 2, 3 AS [Foo]

I get this result table :

--------------------------------------------
|(No Column Name) | (No Column Name) | Foo |
--------------------------------------------
|       1         |        2         |  3  |
--------------------------------------------

Which is not what I want. If I change it for this :

SELECT
1 AS [Foo],
2 AS [Foo],
3 AS [Foo]

I get this result table :

-------------------
| Foo | Foo | Foo |
-------------------
|  1  |  2  |  3  | 
-------------------

Which is still not what I'm looking for.
How could I change this query so that my output table would look like this :

-------
| Foo |
-------
|  1  |
|  2  |
|  3  | 
-------

Upvotes: 0

Views: 962

Answers (1)

John Woo
John Woo

Reputation: 263693

you need an UNION

SELECT 1 AS Foo
UNION ALL
SELECT 2 AS Foo
UNION ALL
SELECT 3 AS Foo

Upvotes: 3

Related Questions