This is how to enter a specific value in a column depending on the value of another column.
So we have a table called ‘t_main’ in a database called ‘db_sample’, and it looks something like this.
Name | Stat1 | Status |
---|---|---|
Module 1 | 23 | |
Module 2 | 50 | |
Module 3 | 31 |
And we want to see if we can add the value ‘Full’ to the entries that have 30 or more in the stat column.
We can do this with this simple command
UPDATE `t_main` SET `Status` = 'Full' WHERE `Stat1` >= 30;
Now we end up with something like this
Name | Stat1 | Status |
---|---|---|
Module 1 | 23 | |
Module 2 | 50 | Full |
Module 3 | 31 | Full |
That’s it!