Mysql – Loading a table with input from two different input files

MySQL

As part of a migration activity i need to load a table in mysql with data from two different input files. As in few fields in the table are loaded from one input file and rest from another. Also the input files are not order wise,what i mean is field 1 in input file 1 might not be the first field in the table. So data needs to be loaded into proper fields in the table from input files.
Hope my question is clear. If anyone can suggest any scripts or anything for this would be helpful
Thanks in advance.

Best Answer

Create a table (t1) with columns matching the columns of one file. Load that file into it.

Create another table (t2) with columns matching the columns of the other file. Load that file into it.

Now create the main table (if it does not already exist). Load it with something like

INSERT INTO main (a,b,c,d,e)
    SELECT t1.x, t2.y, t1.z, t1.w, t2.v  -- in whatever order is correct
        FROM t1
        JOIN t2 ON ... -- explain how the two tables (files) need to be paired up.