Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
This is my Table with 2 columns::
A B
5 P
6 Q
7 R
8 .


Write a query to display the following columns in a single column using CTE

Output As:
Result
5
6
7
8
P
Q
R
.


It would be great help if i get it.Here i used union all to show the output...but i want to know using CTE.
Thank you for helping me to get the desired output.
Posted
Comments
Jörgen Andersson 23-Mar-15 12:41pm    
Why? Union all is a perfectly good solution.
Mehdi Gholam 23-Mar-15 13:01pm    
I agree.
F-ES Sitecore 23-Mar-15 13:04pm    
Because his coursework is about CTE :)
Jörgen Andersson 23-Mar-15 13:43pm    
Probably. :-)
pn46 23-Mar-15 15:14pm    
Since i was asked by my mentor to do so.. I tried..but dint find the perfect solution.So needed some help here.
Thank You Anyways :)

1 solution

Totally pointless, but here you are:
SQL
With A as (
    SELECT  A result
    FROM    MYTable
    )
,B as (
    Select  B Result
    FROM    MyTable
    )
SELECT  Result
FROM    A
UNION
SELECT  Result
FROM    B
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900