Q:

Mysql insert on duplicate key update and delete if key not exists

given these two queries:
INSERT INTO table1 (id,name,units,price,category_id) 
VALUES 
    (1,'name1', 'units1', 'price1', 6)
    (2,'name2', 'units2', 'price2', 6)
    (3,'name3', 'units3', 'price3', 6)
    (4,'name4', 'units4', 'price4', 6)
ON DUPLICATE KEY UPDATE 
    product_name=VALUES(name), 
    units=VALUES(units), 
    price=VALUES(price)

and
DELETE FROM table1 WHERE category_id = 6 AND id NOT IN(2,4)

Is there any way to combine these two query into a single query?

A:

You can't, but you can put them on one transaction.
Transaction mean if one of the commands fail all the commands will not commit.
Only when all the commands passed well they will commit. 

