I have a mysql table with following columns:
filterid productid value groupid
I want to export the rows of this table (Only selected rows) to a CSV file.
I know how to do the exporting part.
For example, if I have exported the rows based on product ID, let say exported rows are:
4 13307 USA|Quebec|Rest of Canada 750
9 15963 USA|Quebec|Rest of Canada 1
9 13618 USA|Quebec|Rest of Canada 1
9 16210 USA|Quebec|Rest of Canada 1
9 16666 USA|Quebec|Rest of Canada 1
Out of total 100 rows.
Now, I have exported this content into a CSV file and want to import it back to my mysql table where it should update only rows matching with the product id’s which are in my exported CSV file without disturbing rest of the table content.
Is it possible to do that?
After googling, what I found is that I can import a CSV to a table using this code
LOAD DATA LOCAL INFILE 'filename.csv' INTO TABLE my_table FIELDS
TERMINATED BY ','
ENCLOSED BY ''
LINES TERMINATED BY '\n'
Please suggest a way to achieve this.
I can provide you with more sample code if you need.
Thank You!
I think he was asking the question because he didn’t know how to use
INFILEwith aWHEREclause:If you want to use a script to do what you mentioned, you can try the following:
It should at least point you in the right direction..