I would like to get a help for a mysql ( using version 8 ) case. I have following table
CREATE TABLE taskStatus ( task_id int NOT NULL,employee_id int NOT NULL, completed_on datetime DEFAULT NULL,task_status bit(1) NOT NULL, PRIMARY KEY (task_id,employee_id)) ENGINE=InnoDB
I would like to insert a row if (task_id,employee_id) does not exist but if it exists then it should update the row only if task_status = 0. By this way I want to ensure that if somebody set task_status = 1 for a row then never change the completed_on value.
INSERT INTO ….. ON DUPLICATE KEY UPDATE will not work as it won’t take a where clause.
For me, UPDATE should happen only if one column value satisfied a criteria but INSERT can happen without that condition.
I understood that I could do it using multiple queries but I have to do it for lot of rows.
My understanding is that if I can do it in a single query then I can run it as a batch. If I do it in multiple query then I can not do it as batch and
whole thing may be too slow.
Could someone please suggest some pointers.