MySQL Query to update record if exists else add new based on multiple unique keys?

Viewed 22

The below Query will update if exists, else add a new one. Now for this uniqe key is required for one column, can i add unique keys for multiple columns & achieve the same or any other way to achieve the same?

INSERT INTO products (type, brand, model, quantity) 
VALUES("Laptop", "DELL", "Vostro", 10) ON DUPLICATE KEY UPDATE quantity = quantity + 5;

Reference Link: https://thispointer.com/insert-into-a-mysql-table-or-update-if-exists/

lets assume we need to check all 3 fields i.e. type, brand, modelno, if all 3 are same then only update else add a new record.

Any help shall be really appreciated...Thanks

0 Answers
Related