Update many records, with one value

mysqlFrom time to time you might need to update multiple records in a MySQL database, with the same value.  Using this method will allow you to update all the records in one go.

 


Example

For this example, we have a products table called products_table, that has the following fields:

  • id
  • product
  • product_code
  • category
  • quantity

We would like to put them all in the same category called 'General'.

 

phpMyAdmin

Using phpMyAdmin, browse to the correct table.

  1. Select the SQL tab.
  2. Enter the following SQL code in the box provided.
UPDATE products_table SET category = 'General' WHERE id > 0

Note that omitting the use of a WHERE statement, will ensure that all records are updated.

 

If you wanted to change category from General to Misc you could run the following SQL code:

UPDATE `products_table` SET category = 'Misc' WHERE `category`='General'

 

Thanks for visiting.