in Education by
I quite often have rows of code like the following: UPDATE my_table SET name = 'x' WHERE Original = 'a' UPDATE my_table SET name = 'y' WHERE Original = 'b' UPDATE my_table SET name = 'z' WHERE Original = 'c' UPDATE my_table SET name = 'k' WHERE Original = 'd' UPDATE my_table SET name = 'm' WHERE Original = 'e' UPDATE my_table SET name = 'n' WHERE Original = 'f' Can I combine/shorten this code into one UpDate statement - or are they best just left as they are? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
UPDATE my_table SET name = CASE WHEN Original = 'a' THEN 'x' WHEN Original = 'b' THEN 'y' ... END That will update EVERY row. So if there's an Original value you haven't specified, it will be set to NULL. So you might want to limit the update to just those you want to update, with a WHERE clause, like so: WHERE Original IN ('a', 'b', ...) OR, as an alternative, you could use an ELSE statement, which leaves the name value as is, if it doesn't have a match in the WHEN statements, like so: CASE WHEN Original = 'a' THEN 'x' WHEN Original = 'b' THEN 'y' ... ELSE name END

Related questions

0 votes
    Bitmaps can be combined with regular B+-tree indices for relations where a few attribute values are ... Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    The database system must take special actions to ensure that transactions operate properly without interference ... Concept topic in chapter Transactions of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
    regmatches(number, gregexpr(pattern = “2.?2”,text = number)) Is this an example of non-greedy quantifier? If yes, then why and what would be the equivalent greedy quantifier?...
asked Oct 16, 2020 in Technology by JackTerrance
0 votes
    ALU and control unit of most of the computers are combined and are embedded on a single . (a) Monochip (b) ... ) ALU (e) Microfilm Select the correct answer from above options...
asked Dec 12, 2021 in Education by JackTerrance
0 votes
    You need to combine the first_name and last_name columns in the employees table and display the columns as a combined ... | and || Select the correct answer from above options...
asked Dec 1, 2021 in Education by JackTerrance
0 votes
    From the circuits shown below, find the combined Z-parameter Z11. (a) 8 (b) 18 (c) 28 (d) 38 I got ... Questions for GATE EC Exam, Network Theory MCQ (Multiple Choice Questions)...
asked Oct 13, 2021 in Education by JackTerrance
0 votes
    From the circuits shown below, find the combined Z-parameter Z12. (a) 4 (b) 5 (c) 6 (d) 7 I have ... Questions for GATE EC Exam, Network Theory MCQ (Multiple Choice Questions)...
asked Oct 13, 2021 in Education by JackTerrance
0 votes
    From the circuits shown below, find the combined Z-parameter Z21. (a) 7 (b) 6 (c) 5 (d) 4 The ... Questions for GATE EC Exam, Network Theory MCQ (Multiple Choice Questions)...
asked Oct 13, 2021 in Education by JackTerrance
0 votes
    From the circuits shown below, find the combined Z-parameter Z22. (a) 38 (b) 28 (c) 18 (d) 8 This ... Questions for GATE EC Exam, Network Theory MCQ (Multiple Choice Questions)...
asked Oct 13, 2021 in Education by JackTerrance
0 votes
    In the circuit given below, the voltage across the 18 Ω resistor is 90 V. The voltage across the combined circuit ... GATE EC Exam, Network Theory MCQ (Multiple Choice Questions)...
asked Oct 12, 2021 in Education by JackTerrance
0 votes
    Define turbo charging in combined gas turbine and diesel cycles?...
asked Jan 29, 2021 in Education by JackTerrance
0 votes
    Name two combined power cycles?...
asked Jan 29, 2021 in Education by JackTerrance
0 votes
    ________ dump, writes out SQL DDL statements and SQL insert statements to a file, which can then be ... , Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
...