azirion
azirion

Reputation: 109

Update all mysql records from one table into another

Table1 contains all the fields from table2. I need to update table1 with the all the records from table2. I found this:

UPDATE 
    table1 
INNER JOIN 
    table2 ON (table2.id = table1.id)
SET 
    table1.field1 = table2.field1,
    table1.field2 = table2.field2;

But I have too many fields and this would take forever to write. How can I update all the fields from table2 into table1? I can´t seem to find the answer, please help.

Upvotes: 0

Views: 55

Answers (1)

Hart CO
Hart CO

Reputation: 34784

I'm not terribly familiar with MySQL, but if you can get a list of column names, perhaps with:

SHOW COLUMNS FROM mytable FROM mydb

Then you can paste those into Excel and build your query, just paste your field names in column A , throw this in B1:

="table1."&A1&" = table2."&A1&","

And copy down.

Upvotes: 1

Related Questions