我有两个表,mileage_registrants和date_import。两个表都有字段'user_id'和'department'。我想要做的是通过匹配两个表的user_id,从表data_import更新mileage_registrants部门的部门信息。
我得到的查询是错误的。如何编写正确的查询?感谢
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)
答案 0 :(得分:1)
这适用于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