Alexander Donets
Alexander Donets

Reputation: 637

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 bday, height, surname to my database and populate a csv file with them.

Is it possible to load those into a file without changing the id's of the users?

Upvotes: 1

Views: 46

Answers (1)

ScaisEdge
ScaisEdge

Reputation: 133370

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;

Upvotes: 2

Related Questions