需求: 现有两张表,一张学生表(student),一张学生类型(category)表
category student
|id | 主键id | |id | 主键id |
|code |类型编码 | |category_code | 学生类型编码 |
|name |类型名称 | |category_name | 学生类型名称 |
现在需要将category表中的name通过student表中的category_code添加到student表中
update student s
inner join (SELECT c.id,c.code,c.name FROM category c) ca on (ca.code= s.category_code)
set
s.category_name = ca.name
where s.id= "123456"