从CSV导入列到现有的MySQL表中 [英] Import Column from CSV into existing MySQL Table

查看:165
本文介绍了从CSV导入列到现有的MySQL表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 MySQL Researcher:

ID | FirstName | Surname | Email | Position | Summary | ... + many more columns.

还有一个 CSV 文件,其中包含以下列:

And a CSV file with the columns:

Email | Summary

在MySQL表中,所有行的Summary列均为空白,当前数据存在于CSV中.

In the MySQL table, the Summary column is blank for all rows, the data currently exists in the CSV.

我想使用Email将行中的Summary列从CSV文件导入到MySQL表中.

I would like to import the Summary column from the CSV file, into the MySQL table, using Email to match the rows.

我该如何实现?

推荐答案

感谢您将我指向正确的花式裤子.

Thanks for pointing me in the right direction fancyPants.

我最终像这样解决了它:

I eventually solved it like this:

  1. 使用来自CSV的列在数据库中创建一个名为Researcher_Temp的新表.
  2. 使用phpMyAdmin将LOAD DATA导入CSV到Researcher_Temp
  3. 运行以下查询,将Researcher_Temp中的摘要数据添加到我的主Researcher表中:
  1. Created a new table in the DB called Researcher_Temp with columns from the CSV.
  2. Used phpMyAdmin to import the CSV using LOAD DATA into Researcher_Temp
  3. Ran the following query to add the summary data from Researcher_Temp into my main Researcher table:

UPDATE Researcher INNER JOIN Researcher_Temp on Researcher_Temp.Email = Researcher.Email SET Researcher.Summary = Researcher_Temp.Summary;

UPDATE Researcher INNER JOIN Researcher_Temp on Researcher_Temp.Email = Researcher.Email SET Researcher.Summary = Researcher_Temp.Summary;

然后我删除了Temp表.

I then deleted the Temp table.

这篇关于从CSV导入列到现有的MySQL表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆