开发者

Insert select with a twist question

I Want to copy all the data of a table (with a certain id ofcourse) into the same table, but with a slightly difference.

I have this table (product_quantity):

id----groupId----productId----quantity

1 ----- 2 ------------2--------------5

What i want to do is to copy all the data that have groupId=2, insert it in the table with groupId=3

So I found that I could do a select-insert

insert into product_quantity (groupId, productId, quantity) SELECT groupId, productId, quantity FROM prouct_quantity WHERE groupId=2

But this will only make duplicates.

Is it possible to use this insert-select, but also insert a gro开发者_StackOverflow中文版upId=3, with just one query?

Thanks in advance!


Try this sql query:

insert into product_quantity (groupId, productId, quantity) 
select 3, productId, quantity from product_quantity where groupId = 2 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜