table name: mysample.
table columns: id - PK, names - pk, age.
inside mysample:
id names age
1 Nicole 19
2 Sam 20
3 Mark 15
I'm using MySQL Workbench.
That is the result after I use this query:
load data local infile 'C:/Users/mysample.csv' into table mysample fields terminated by ','
enclosed by '"'
lines terminated by '\n'
ignore 1 lines
(names, age)
This will load the csv file into the database. I modified the csv file and made these changes.
inside modifies csv file:
names age
Nicole 20
Sam 15
Mark 13
May 10
What I want to achieve is that the rows Nicole, Sam and Mark will be updated thus having no similar names. That's why I made the names as the primary key. I searched and found the REPLACE query syntax.
load data local infile 'C:/Users/mysample.csv' replace into table mysample fields
terminated by ','
enclosed by '"'
lines terminated by '\n'
ignore 1 lines
(names, age)
But I got these results on my database:
id names age
1 Nicole 19
2 Sam 20
3 Mark 15
4 Nicole 20
5 Sam 15
6 Mark 13
7 May 10
How can I specify the REPLACE query to replace the rows with the same primary key?