简体   繁体   English

将所有mysql记录从一个表更新到另一个表

[英]Update all mysql records from one table into another

Table1 contains all the fields from table2. 表1包含表2中的所有字段。 I need to update table1 with the all the records from table2. 我需要使用来自table2的所有记录来更新table1。 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? 如何将所有字段从表2更新到表1? I can´t seem to find the answer, please help. 我似乎找不到答案,请帮忙。

I'm not terribly familiar with MySQL, but if you can get a list of column names, perhaps with: 我对MySQL并不十分熟悉,但是如果您可以获得列名列表,也许可以:

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 : 然后,您可以将它们粘贴到Excel中并构建查询,只需将字段名称粘贴到A列中,然后将其扔到B1

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

And copy down. 并抄下来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM