Solved

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

Posted on 2016-09-15
7
43 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 28

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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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 28

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Use SSRS to email customers? 4 30
SQL Query 9 29
Begin Transaction 12 26
Datatable / Dates ? 4 32
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
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…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

739 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