Solved

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

Posted on 2011-09-09
3
372 Views
Last Modified: 2012-05-12
Can I create a table or view  from a  UNION statement?
0
Comment
Question by:zachvaldez
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 250 total points
ID: 36513301
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
 

Author Comment

by:zachvaldez
ID: 36514102
Definitely work! Now I'll have the flexibility for creating datasource.
0
 

Author Closing Comment

by:zachvaldez
ID: 36514111
Thanks!
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question