Difference between INSERT INTO and LOAD DATA from CSV in MySQL

890 Views Asked by At

I have two different tables, created by Load DATA commands,I am trying to run the following code:

select t.name as Name, sum(t.amount) as Total from 
(select t2.name, t1.vendorname, t1.amount  from bco_ifs_payment_data t1
join VendorName t2 on t1.vendorname like concat('%',t2.name,'%' )) as t 
group by t.name;

The code works and returns rows when I use INSERT INTO command to insert data into the VendorName table , but when I use LOAD DATA command to insert data in the VendorName table no rows are returned in the JOIN even though same data is inserted in the table

THe Vendor_Names CSV has only one column. LOAD Data query is as following:

create Table vendorname(name nvarchar(100));
LOAD DATA LOCAL INFILE 'F:\Payments\_Global Payment\\Data\\Data\\Vendor_Names.csv' 
INTO TABLE vendorname FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'; 
update vendorname SET name = UPPER(name);  

The INSERT query is as following:

 INSERT INTO vendorname VALUES ('DELOITTE');
 INSERT INTO vendorname VALUES ('CBRE');
2

There are 2 best solutions below

0
On

Got it, had to include the following code:

select t.name as Name, sum(t.amount) as Total from 
(select t2.name, t1.vendorname, t1.amount  from bco_ifs_payment_data t1
join vendorname t2 on t1.vendorname like concat('%',REPLACE(t2.name,'\r','') ,'%' )) as t 
group by t.name;
0
On

can you post both queries, it might be that sequence of value in csv is in different order then what is in insert into query