Can I create a table or view from a UNION statement?

Can I create a table or view  from a  UNION statement?
zachvaldezAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Patrick MatthewsConnect With a Mentor Commented:
Yes.

CREATE VIEW dbo.MyView AS
SELECT a, b, c
FROM Table1
UNION
SELECT a, b, c
FROM Table2

Open in new window


Creating a table...

SELECT z.a, z.b, z.c
INTO NewTable
FROM
    (SELECT a, b, c
    FROM Table1
    UNION
    SELECT a, b, c
    FROM Table2) AS z

Open in new window

0
 
zachvaldezAuthor Commented:
Definitely work! Now I'll have the flexibility for creating datasource.
0
 
zachvaldezAuthor Commented:
Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.