I have a CSV file with mappings from project ids to some new category codes.
e.g.
Project Id, New Code
1, 035
2, 029
3, 023
4, 035
5, 029
....
The above is in a CSV file/excel file
I have a table of projects with these project ids and I want to add a new column with the releavan new code.
Is there any way I can do that with mysql?
Here is a quick-and-dirty solution, using the CONCATENATE functionality of Excel:
Assuming you have Project ID in column A and New Code in column B, enter the following for column C:
Then copy and paste that for all the rows in your excel spreadsheet. That generates SQL statements you can then use to bulk update your table. Copy out the text into a script and then let mysql execute it.
You will end up with a script that looks something like this:
This of course assumes you already have the new column in your table. If not, use an alter table statement to add it:
Note: I do not reccomend this method if you want to do it repeatedly – but if its just a once-off thing, then a quick solution like this works just fine.