I want to embed data in a mysql table, but I cannot find a way to make relationships from a single row
Suppose I have a file.tab file, it contains data in the format
parent_1 parent_details_1 child_1.1 child_details_1.1 child_1.2 child_details_1.2 parent_2 parent_details_2 child_2.1 child_details_2.1 parent_3 parent_details_3 child_3.1 child_details_3.1 child_3.2 child_details_3.2 child_3.3 child_details_3.3
what I want to achieve is to insert data into two tables, for example
parent_table +---+-----------+-------------------+ |id | name | details | +---+-----------+-------------------+ | 1 | parent_1 | parent_details_1 | | 2 | parent_2 | parent_details_2 | | 3 | parent_3 | parent_details_3 | +---+-----------+-------------------+ child_table +---+-----+-----------+-------------------+ |id | pid | name | details | +---+-----+-----------+-------------------+ | 1 | 1 | child_1.1 | child_details_1.1 | | 2 | 1 | child_1.2 | child_details_1.2 | | 3 | 2 | child_2.1 | child_details_2.1 | | 4 | 3 | child_3.1 | child_details_3.1 | | 5 | 3 | child_3.2 | child_details_3.2 | | 6 | 3 | child_3.3 | child_details_3.3 | +---+-----+-----------+-------------------+
the first two columns are for the parent, and after that two or two columns refer to the child ones, but I donβt know how many parents the parent has.
I tried to upload the file this way.
LOAD DATA INFILE '/tmp/file.tab INTO TABLE ...
but what to do next, I have no idea.
so kindly help me in this matter.
source share