[英]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
: 使用带有
Join
的Update
:
update unknown u
join dictionary d on u.item = d.item
set u.description = d.description
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.