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 groupId=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