MySQL UPDATE

How to write a query to update data in MySQL.

The UPDATE clause will allow you to update existing records. The first query below shows you how to change the value of a whole column. The second query shows you how to change more than 1 whole column.

UPDATE tablename SET column='value'

UPDATE tablename SET column1='value', column2='value'

Most of the time you will want to add the WHERE clause to specify which rows in a column you want changed. The following query shows you how the syntax for a query to update certain rows.

UPDATE tablename SET column1='value1' WHERE column2='value2'

If you are only updating one record then you should apply the LIMIT clause to make sure you don't update any records you shouldn't.

UPDATE tablename SET column1='value1' WHERE column2='value2' LIMIT 1

The following examples will use the following database.



UPDATE query

MySQL Code

Say you want to change Brian Grossman's age to 33.

$query="UPDATE users SET age='33' WHERE id='4';




Result




 
Bookmark this page:
   
 
Shared Hosts
Lunarpages.com Web Hosting

Domain Registrars
PPC Networks
Logos
Affiliate Networks
Resources