Categories
Uncategorized

Selecting and Entering Values – MYSQL

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!

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s