Answer the question
In order to leave comments, you need to log in
Which sql commands are more efficient?
Hello, I've run into this issue.
You need to add data to the tables if they are not there (there is a unique identifier in the data).
What is the best way to do this?
1) SELECT query to check for existence, and then add
2) add without checking.
And you need to delete the data if it is in the table (there is a unique identifier in the data).
What is the best way to do this?
1) query SELECT to check for existence, and then delete
2) delete without checking.
MySql database, InnoDB tables
Answer the question
In order to leave comments, you need to log in
The path in the table `table` field `field1` is defined as UNIQUE (or PRIMARY KEY).
Adding only new
INSERT IGNORE INTO `table` (`field1`, `field2`, `field3`)
VALUES (`valA1`, `valA2`, `valA3`), (`valB1`, `valB2`, `valB3`)
INSERT INTO `table` (`field1`, `field2`, `field3`)
VALUES (`valA1`, `valA2`, `valA3`), (`valB1`, `valB2`, `valB3`)
ON DUPLICATE KEY UPDATE `field2` = VALUES(`field2`), `field3` = VALUES(`field3`)
DELETE FROM `table` WHERE `field1` IN (`valA1`, `valB1`)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question