Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Colsolidate 2 views SQL

Posted on 2011-03-01
2
Medium Priority
?
239 Views
Last Modified: 2012-06-22
Dear Experts

I have two views with exactly the same amount of columns and column names.

Each of the views hold different data and I would like to create another view to consolidate the data.  Is this possible.

For Example

Table A                      Table B
pRef                           pRef
pAddress1                pAddress1
pAddress2                pAddress2
pTown                       pTown


Am I able to consolidate this data into (Table C)

Thanks


0
Comment
Question by:grantballantyne
2 Comments
 
LVL 25

Accepted Solution

by:
reb73 earned 1000 total points
ID: 35007014
SELECT * INTO dbo.TableC
FROM
(SELECT * FROM dbo.TableA
 UNION ALL
 SELECT * FROM dbo.TableB
) as Tmp
0
 
LVL 8

Assisted Solution

by:Forefront_Data_Solutions
Forefront_Data_Solutions earned 1000 total points
ID: 35007021
The simplest way would be to use the UNION operator.  Copy the SQL from View A add the UNION operator, then copy the SQL from View B.  Like this:

Select somestuff
from ATable

UNION

Select someotherstuff
from BTable


The most efficient way would be to analyze the data from the original two tables and write a query that retrieves the desired data.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

773 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