-- import the csvfile to this temp table , the column just like your csv header
create table IF NOT EXISTS my_db.csv_file (
id int auto_increment primary key,
vendor_name varchar(200),
product_name varchar(200),
product_price double
);
-- table one
create table if not exists my_db.product(
id int auto_increment primary key,
vendor_id int, -- foreign
name varchar(200),
price double
)
-- table two
create table if not exists my_db.vendor(
id int auto_increment primary key,
name varchar(200)
)
-- import csv data ,you can use LOAD command
insert into my_db.csv_file(vendor_name,product_name,product_price)values
('A','book',1.00),
('B','computer',2.00),
('C','phone',3.00);
-- step 1:
insert into my_db.vendor(name)
(select vendor_name from my_db.csv_file group by vendor_name);
-- step 2:
insert into my_db.product(vendor_id , name , price)
(select vendor.id,temp.product_name,temp.product_price from my_db.csv_file as temp left join my_db.vendor as vendor on vendor.name = temp.vendor_name);