[英]How to update a field of a table by using data from another table(MYSQL)
I have two tables, mileage_registrants and date_import. 我有两个表,mileage_registrants和date_import。 Both tables have field 'user_id' and 'department'.
两个表都具有字段“ user_id”和“部门”。 What I want to do is to update department of mileage_registrants with department info from table data_import by matching the user_id of both tables.
我想做的是通过匹配两个表的user_id用表data_import中的部门信息更新Mileage_registrants的部门。
The query I got is wrong. 我得到的查询是错误的。 How to write the correct query?
如何编写正确的查询? thanks
谢谢
Update mileage_registrants
SET mileage_registrants.department = test_date_import.department
INNER JOIN test_date_import
ON(test_date_import.user_id = mileage_registrants.user_id)
This works in SQL Server, and should work in MySQL: 这在SQL Server中有效,并且在MySQL中有效:
UPDATE
mileage_registrants
SET
m.department = t.department
FROM
mileage_registrants m
INNER JOIN
test_date_import t
ON
t.user_id = m.user_id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.