Solved

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

Posted on 2016-09-15
7
30 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 17

Accepted Solution

by:
Pawan Kumar Khowal 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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 17

Expert Comment

by:Pawan Kumar Khowal
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 24

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
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 SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

706 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