Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2016-09-15
7
Medium Priority
?
46 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 30

Accepted Solution

by:
Pawan Kumar earned 1000 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 500 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
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
LVL 4

Assisted Solution

by:Steven Kribbe
Steven Kribbe earned 500 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 30

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to shrink a transaction log file down to a reasonable size.

722 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