Solved

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

Posted on 2016-09-15
7
45 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
[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
7 Comments
 
LVL 29

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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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 29

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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how the fundamental information of how to create a table.

632 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