I just got stuck in a problem, where there are two ways of solving this.
Let me first explain the case,
I have a DB table
consisting of some columns say id, name, address, priority
. Here name
and address
is not unique but name + address + priority
is unique.
Input provided to me is name and list of addresses. Now, what I have to do is to arrange name and address in the same order as given in input in my DB table.
There are two ways of solving:
- selecting on the basis of name and address and make update queries for those data which are changed and execute them.
- delete the data corresponding to name and address from table and insert the data with new priority.
I know that one update
is faster than delete + insert
but here in this case there is one select query too.
My intuition is that 1st method will be more fast but I don't have any technical details about it.
Am I missing something?