Click here to Skip to main content
15,891,529 members
Articles / Programming Languages / SQL
Alternative
Tip/Trick

UNION ALL between Two CTEs

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
31 Aug 2010CPOL 9.7K   2   1
The same thing can be done with even less SQL.WITH CTE AS( SELECT * from TableA UNION ALL Select * from TableB)select * from CTE
The same thing can be done with even less SQL.

SQL
WITH CTE AS
( 
  SELECT * from TableA
  UNION ALL
  Select * from TableB
)
select * from CTE

License

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


Written By
Web Developer
United States United States
Erik lives in Redmond, Washington. He works as a Senior Software Engineer specializing in C++, COM, ATL and the middle-tier and now .NET. When he isn't coding for work, he can be found trying to extend Internet Explorer with yet another Desk band or simplifying his development process with ATL Object Wizards.

He spends his free time snowboarding, mountain biking, and online gaming.

Comments and Discussions

 
GeneralI know that it can be done that way. but intention of my tri... Pin
Hiren solanki31-Aug-10 20:23
Hiren solanki31-Aug-10 20:23 
I know that it can be done that way. but intention of my trick is to just make you know how to make union of two CTEs,
This is just scenario Example.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.