MySql 通过另一个 table 的加入进行更新

MySql update with join from another table

我在我的 WorkSheetTransaction table 中添加了一列,并希望用部门 table 构建的名称填充它。两个 table 都已填充了联接字段 DepartmentId。

以下查询运行正常,但未更新任何行。为什么不呢?

update WorkSheetTransactions
inner join Departments on WorkSheetTransactions.DepartmentId = Departments.DepartmentId 
set WorkSheetTransactions.DepartmentName = (Departments.GL_Account + '-' + Departments.DepartmentName)

我尝试了很多变体,但我就是看不出哪里出了问题。顺便说一句,连接字段在 table 中都是一个整数,所有其他 2 个字段都是 var_chars.

在mysql中,您应该使用concat来连接字符串:

UPDATE WorkSheetTransactions
INNER JOIN Departments
ON WorkSheetTransactions.DepartmentId = Departments.DepartmentId 
SET WorkSheetTransactions.DepartmentName = concat(Departments.GL_Account, '-', Departments.DepartmentName)