In this article we will see "How to use UPDATE in MySql" to update data in a table and "UPDATE query syntax with example".

UPDATE query in MySql syntax

The UPDATE statement is used to update data in a table, syntax is as follows.


UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;


UPDATE query in MySql example

The UPDATE statement is used to update data in a table, as shown below:


/*Example EMPLOYEE table */
+----+--------+---------+
| id | name   | email   |
+----+--------+---------+
|  1 | name-1 | email-1 |
|  2 | name-2 | email-2 |
|  3 | name-3 | email-3 |
|  4 | name-4 | email-4 |
|  5 | name-1 | email-5 |
|  6 | name-2 | email-6 |
+----+--------+---------+



We will now apply UPDATE on above table to update name column based on id:


UPDATE EMPLOYEE SET name = 'updated name' WHERE id = 4;

Output: Output will be something like this:


/* Table data after updation*/
+----+--------------+---------+
| id | name         | email   |
+----+--------------+---------+
|  1 | name-1       | email-1 |
|  2 | name-2       | email-2 |
|  3 | name-3       | email-3 |
|  4 | updated name | email-4 |
|  5 | name-1       | email-5 |
|  6 | name-2       | email-6 |
+----+--------------+---------+



In this article we have seen "How to use UPDATE in MySql" and "UPDATE query syntax with example", in upcoming articles we will see more about Mysql syntax and queries with example.
  • By Techburps.com
  • Oct 20, 2017
  • MySql