Home > Software design >  Updating issue using 3 columns with ELSEIF and ELSE
Updating issue using 3 columns with ELSEIF and ELSE

Time:02-23

My knowledge is lacking here I’ve Googled this for 3 days.

I’m using these 6 column names.

id1_TA_player, 1_TA_percent,
id2_TA_player, 2_TA_percent,
id3_TA_player, 3_TA_percent

If the selected number equals 1 of the columns it will not equal the other columns.

I know this code is wrong below, but this will show you exactly what I want to do.

Sample code

UPDATE test
SET 1_TA_percent = 5 WHERE id1_TA_player = 1
ELSEIF
SET 2_TA_percent = 10 WHERE id2_TA_player = 1
ELSE
SET 3_TA_percent = 20 WHERE id3_TA_player = 1
END

Thank you for helping me in advanced I really appreciate your help.

CodePudding user response:

Are you looking for this:

UPDATE test SET
`1_TA_percent` = IF(`id1_TA_player` = 1, 5, `1_TA_percent`),
`2_TA_percent` = IF(`id2_TA_player` = 1, 10, `2_TA_percent`),
`3_TA_percent` = IF(`id3_TA_player` = 1, 20, `3_TA_percent`)
  • Related