Reputation: 1515
I have to delete a lot of data based on id value. Which one is the fastest :
DELETE FROM myTable WHERE id = '10' OR id = '20' OR id = '43' OR id = '54' .......
or
DELETE FROM myTable WHERE id = '10'; DELETE FROM myTable WHERE id = '20'; ........
If you have an another solution, don't hesitate to tell me.
(the id here is not primary key or indexed, is a foreignkey because it references a word and I can have multiple entry for one word in this database)
I use MySQL but I want that my query can be applied on other RDBMS
Upvotes: 2
Views: 160
Reputation: 7068
First one should be faster,
Having one statement is better than having set of statements in terms of Query Optimizer output.
Upvotes: 0
Reputation: 40970
The first one is faster but I would like to use IN
operator like this for more readability
though with same performance
DELETE FROM myTable WHERE id in ('10','20','30',...)
Upvotes: 5