Quickest way to duplicate a MySQL Record

旧巷老猫 提交于 2019-12-25 01:15:32

问题


Simple question, i have a query with some WHERE and i need to duplicate it with a change to 1 field to a different value? There is a unique increment ID field as well which I cannot duplicate.


回答1:


Something along these lines should work. This will give you access to the row that you want to duplicate, and you just select the values to insert for the new row, replacing one of them.

INSERT tblData
( -- Lets pretend Column1 is your key
   Column2
   , Column3
)
SELECT
   Column2
   , Column3 + 5 /*Replace this with whatever value is you want*/
FROM tblData
WHERE Column1 = @Id



回答2:


INSERT INTO table(field1,field2)
SELECT field1*x, field2 /*Replace accordingly*/
FROM table
WHERE key = @Id


来源:https://stackoverflow.com/questions/9670731/quickest-way-to-duplicate-a-mysql-record

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!