Is there a way to simplify these two statements into one?
UPDATE items
SET D1 = 'AAA'
WHERE D1 = 'BBB'
UPDATE items
SET D2 = 'AAA'
WHERE D2 = 'BBB'
I want to set D1 to AAA ONLY IF D1 is BBB, and D2 to AAA only if D2 is BBB.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is about the most efficient way you can do this in one statement:
For the best performance, make sure you have separate indexes on
D1andD2. The query planner can do an index merge in this case. Don’t use only a multi-column index, or the query planner will have to fall back on a table scan.