简体   繁体   English

MySQL用第一张表中的数据填充第二张表

[英]MySQL fill out the second table with data from the first table

There are two tables in the MySQL db: MySQL数据库中有两个表:

Dictionary Table:
**item | description**
--------------------
item1 | Description1
item2 | Description2
........
item1000000 | Description1000000


**Unknown**:
**item | description**
--------------------
item33 | NULL
item1234 | NULL
item8599 | NULL

I need to fill out the description column of Unknown table by the correspondent data of Dictionary table. 我需要通过Dictionary表的对应数据填写Unknown表的描述列。

How to make it with one query? 如何通过一个查询做到这一点?

So the result would be 所以结果是

item | description
--------------------
item33 | Description33
item1234 | Description1234
item8599 | Description8599

You can use the multiple-table UPDATE syntax to join the tables: 您可以使用多表UPDATE语法来联接表:

UPDATE Unknown JOIN Dictionary USING (item)
SET    Unknown.description = Dictionary.description

Use an Update with a Join : 使用带有JoinUpdate

update unknown u 
join dictionary d on u.item = d.item
set u.description = d.description

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

相关问题 将第二个 MySQL 表中的数据添加到第一个表的结果中 - Add data from second MySQL table to the result from the first one 通过ID将数据从第一个MySQL表追加到第二个 - Append data from first MySQL table to second by ID MySQL 外键约束:更新一个表时,用第一个表中的一些数据填充另一个表 - MySQL foreign key constraints : on updating one table, fill another table with some data from the first table MySQL:使用phpMyAdmin使用一个表中的数据填充第二个表 - MySQL: Use data from one table to fill a second table using phpMyAdmin MySQL SELECT全部来自第一个表,并使用第二个表过滤器的特定where子句连接来自第二个表的匹配数据 - MySQL SELECT all from first table and join matched data from second table with specific where clause for second table filter MySQL触发器在插入后将第一张表的数据插入第二张表 - MySQL trigger to insert data of first table into second table after insert 根据MySQL中第一个表的结果选择第二个表中的项目 - Select items in second table based on result from first table in MySQL MySQL - 从第二个表中选择与第一个表匹配的最后一个记录 - MySQL - Select last record from second table matching with first table 用CSV文件中的数据填充MySQL表 - Fill MySQL table with the data from CSV file 如何从 MySQL 中的第二个表打印数据 - how to print data from second table in MySQL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM