Solved

How to merge all multiple tables with a single blank table in SQL?

Posted on 2016-09-15
7
33 Views
Last Modified: 2016-10-04
There are multiple tables, all tables are having same column names with different values, nd I have created one new table with same columns , but I want to put those all data in this new crated single table in SQL. There is no unique id in any of the table. I just want to merge all table data in one sinlge table.

Table names are - Andra Pradesh, Arunachal Pradesh, Assam, Bihar, Chhattisgarh,Delhi,Hariyana,Himachal Pradesh, Karnataka.
      
And all column names are same in all the tables , here is the column names - State, District,Year,January,February,March,April,May,June,July,Aug‌​ust,September,Octobe‌​r,NovemberDecember. And tbl_India this is the new table which I created with the same columns.... I want to add those all data in this new table.
0
Comment
Question by:Shivanand Bhangari
7 Comments
 
LVL 24

Accepted Solution

by:
Pawan Kumar earned 250 total points (awarded by participants)
ID: 41800940
Here is how we can club two or more table together

--

SELECT [col_name] FROM tablea
UNION ALL
SELECT [col_name] FROM tableb

--

Open in new window


Enjoy !!
0
 

Author Comment

by:Shivanand Bhangari
ID: 41801010
executed successfully but the datas are not merged in blank table.
0
 
LVL 35

Assisted Solution

by:Terry Woods
Terry Woods earned 125 total points (awarded by participants)
ID: 41801027
You need to do an insert too:

INSERT INTO blanktable (cola, colb, ...)
SELECT [col_name] FROM tablea
UNION ALL
SELECT [col_name] FROM tableb

Open in new window

0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 4

Assisted Solution

by:Steven Kribbe
Steven Kribbe earned 125 total points (awarded by participants)
ID: 41801029
you have to insert the query results into the new table:

Select * into new_table  
from  (
SELECT [col_name] FROM tablea
UNION ALL
SELECT [col_name] FROM tableb)
0
 
LVL 24

Expert Comment

by:Pawan Kumar
ID: 41801040
Here it is ! Enjoy !

--

INSERT INTO TableName [Cols]
SELECT [col_name] FROM tablea
UNION ALL
SELECT [col_name] FROM tableb


--

Open in new window


--
0
 
LVL 25

Expert Comment

by:Tomas Helgi Johannsson
ID: 41801220
Hi!

Depending on the overall data-size of all the tables you want to merge into the new table.
If the size is over 5 million records then I strongly recommend that you partition the table in such way that you have near-even distribution and the partitioning benefits most or all queries that access the table.

Regards,
      Tomas Helgi
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
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…

914 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now