Alexander Donets Alexander Donets - 2 months ago 18
MySQL Question

MySQL Added additional columns to my table, how to update table

How can I load data from a file without replacing the existing columns but just adding missing values? For example if I already had a table and one of the rows would be

Id: 25, username: john, password: #hash

And then I add new columns like bday, height, surname to my db and populate a csv file with them. Is it possible to load those into a file without changing the id's of the users?


The simplest way is based on import the data in a new temporary table and then perform the update on the orginal table for the column you need join the rows between the 2 tables

eg .

table1 (id, key1, col1, col2_added) 

table_temp(id, key1, col1, col2)

once you imported the files in table_temp you can

update table1
join table_temp = table1.key = table_temp.key
set col2_add = col2;