2
我用相似的标题阅读了这个问题,但它与我的问题不符。mysql复制一些行并更新一列
我有这个表
Robot_Minions
id | type | id_robot_master
1 | catbot | 15
2 | dogbot | 15
3 | batbot | 15
我想要做的就是复制的Robot_Master 15所有Robot_Minons并将它们分配给Robot_Master 16
所以,最终的结果应该像
Robot_Minions
id | type | id_robot_master
1 | catbot | 15
2 | dogbot | 15
3 | batbot | 15
4 | catbot | 16
5 | dogbot | 16
6 | batbot | 16
我可以想到的一种方法是先选择要复制的行,然后遍历它们并运行INSERT blah,然后更新blah WHERE id = last insert id。但是这是1 + 2个查询。有没有更好的方法,最好是一个查询?