0

So i am trying to run a query to move product from category 650 into 652.

This query runs successfully if no duplicate exists.

INSERT INTO catalog_category_product( category_id, product_id, position ) (

SELECT 652 , product_id, position
FROM catalog_category_product
WHERE category_id
IN ( 650 )
)

However, if duplicate exist.. i get duplicate error.

What query do i need to add to tell it to ignore the duplicate and copy the other products?

please help me and write the specific line that i should ad.. i am mysql illiterate.

i hear something about insert ignore into

1
  • Could you please clarify why you seek to insert rows when you actually want to update the field category_id on existing entries?
    – mam08ixo
    Jun 9, 2015 at 14:51

1 Answer 1

0

Try this:

INSERT INTO 
    catalog_category_product( category_id, product_id, position ) 
    (
        SELECT 652 , product_id, position
        FROM catalog_category_product
        WHERE category_id IN ( 650 )
    )
ON DUPLICATE KEY UPDATE category_id = 652
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.