[SOLVED] Merge 2 tables into a new table, when the tables have same set of columns but unordered


I have a MySQL database with 2 tables suppose table1 & table2 each having the same set of 300 columns.
Now what I want to do is create a new table (eg. table3) consisting of rows from table1 and table2.
There is no row matching needed between the two tables. I tried insert, union and various other operations but the catch is the columns are unordered inside the tables. But they have the same set of column names.
Refer to this image
I want to merge the two tables with the rows having data in respective columns, which I am not able to do using UNION or INSERT operation.


After trying a lot of different ways to merge the tables using SQL commands I was unable to find any solution which fulfilled the requirements.
One way in which this can be solved using Python is to load the tables into a Pandas dataframe and then concat these two to a new dataframe.
Pandas merge them properly by matching the column names and then you can reload the table to the database.

Any other solution is appreciated.

Answered By – Navkar Shah

Answer Checked By – David Goodson (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *