I wish to optimize database access by combining this two queries, if possible.
How to combine this two statements into one?
update tbl_priority SET a=1 where j='j1' and priority='1';
update tbl_priority SET g=1 where j='j1';
Any help, suggestion is highly appreciated.
I don't see a nice clean way of combining these two update statements, because the logic in the WHERE
clause does not agree. However, we can retain the common condition j = 'j1'
in the WHERE
clause, and then use a CASE
expression to handle the a
assignement:
UPDATE tbl_priority
SET a = CASE WHEN priority = '1' THEN 1 ELSE a END,
g = 1
WHERE j = 'j1'
Note that this is not ideal because we have a branch of the CASE
expression which assigns a
back to itself. This by itself should not cause a particular record to show up as having been modified though.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments