How can I Loop a column value if Row exists using INSERT ON KEY DUPLICATE UPDATE?
The simple expression which returns what you want is (NOT active).

So, your insert will become (you missed the UPDATE keyword):

INSERT INTO table 
    (name, active) 
VALUES 
    ('max', 1) 
ON DUPLICATE KEY UPDATE
    active = NOT active ;




If you want to have only one row per name, then you need to change the UNIQUE constraint to (name) only. With that change, the above insert will do exactly what you want:


Insert the row except if a row with that name already exists, in which case toggle the existing active value (essentially ignoring the 1 / 0 in the insert VALUES).