我用类似的标题阅读了这个问题,但它与我的问题不符。
我有这张桌子
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 然后 UPDATE blah WHERE id=last insert id。但这是 1+2x 查询。有没有更好的方法,理想情况下作为一个查询?