Rizky Ariestiyansyah
Rizky Ariestiyansyah

Reputation: 766

Auto fill other column in mysql table

I have column in mysql table like this:

| Column A | Column B |
| A        |          | 
| B        |          |
| C        |          |
| D        |          | 
| E        |          |

I want to auto fill the other column using rule if A,C,D then fill X and if B, E fill the Y in the column B field.

The result will be like this:

| Column A | Column B |
|----------|----------|
| A        | X        |
| B        | Y        |
| C        | X        |
| D        | X        | 
| E        | Y        |

Is there are an easy way to do that in MySQL query?

Thank you for help.

Upvotes: 0

Views: 774

Answers (1)

Rob Wood
Rob Wood

Reputation: 415

UPDATE table
SET B = CASE
  WHEN A IN ('A','C','D') THEN 'X' 
  WHEN A IN ('B','E') THEN 'Y'
END

Upvotes: 1

Related Questions