mysql query to insert the value of a column with respect to another column in same table -


below sample table i've been working on,

╔════╦══════════════╦══════╗ ║ kid║  revca       ║ redo ║ ╠════╬══════════════╬══════╣ ║  4 ║ 43453453345  ║  0   ║ ║  2 ║ null         ║  0   ║ ║  5 ║ null         ║  0   ║ ║  7 ║ 5566533      ║  0   ║ ╚════╩══════════════╩══════╝ 

i'm inserting revca value selection table. need update redo 1 each of null values get.

below expected output

╔════╦══════════════╦══════╗ ║ kid║  revca       ║ redo ║ ╠════╬══════════════╬══════╣ ║  4 ║ 43453453345  ║  0   ║ ║  2 ║ null         ║  1   ║ ║  5 ║ null         ║  1   ║ ║  7 ║ 5566533      ║  0   ║ ╚════╩══════════════╩══════╝ 

i'm using update query presently

update \`revca \` set  \` redo\` = 1       \`revca \`= 0; 

i'm looking alternative size of database large. need during insertion itself.

i can use plain sql purpose please me accomplish same. thank you!

as simple as:

update table set redo = 1 revca null 

while inserting:

insert table(kid, revca, redo) select @kid, @revca, case when @revca null 1 else 0 end 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -