MoonPoint Support Logo

 


Shop Amazon Warehouse Deals - Deep Discounts on Open-box and Used ProductsAmazon Warehouse Deals



Advanced Search
February
Sun Mon Tue Wed Thu Fri Sat
 
13
         
2016
Months
Feb


Sat, Feb 13, 2016 10:30 pm

Updating MySQL or MariaDB table entries where a criterion is met

If you want to update all entries in a MySQL or MariaDB database table for entries that meet a specific criterion, you can use a Structured Query Language (SQL) command like the one below:

Update table_name
SET column_name = "new_value"
WHERE colum_name = "old_value";

E.g., suppose I have a table named "Students" in a database I'm currently using with a column in the table named "LastName". Suppose, there are students named Smith whose last name has changed to Lamb and I want to change all instances where an entry in the table has "Smith" in the LastName field to "Lamb". I could use the following SQL command:

Update Students
SET LastName = "Lamb"
WHERE LastName = "Smith";

If you want to change every entry in a table, simply leave off the WHERE clause.

If you want to change multiple fields/columns in a table at the same time, you can separate them with commas in the SET statement, i.e., SET column1=value1,column2=value2,.... E.g., suppose all of the students with a last name of Smith are also undergoing an address change as well as a change to their last name.

Update Students
SET LastName = "Lamb", Address="1234 Cherry Lane"
WHERE LastName = "Smith";

[/software/database/mysql] permanent link

Once You Know, You Newegg AliExpress by Alibaba.com

Shop Amazon Local - Subscribe to Deals in Your Neighborhood

Valid HTML 4.01 Transitional

Privacy Policy   Contact

Blosxom logo