How to update the record in MySQL

In Mysql, we usually have to update the record. There are so many cases when we have to update the record in MySQL. In this post, we will see how we can update the record in MySQL

A Single record or multiple records can be updated by using the update keyword.

Syntax of update statement in MySQL

UPDATE table_name 
SET column_name=newValue
WHERE
filter-condition;
  • UPDATE is the keyword used to update the record.
  • Table_name is the actual table
  • Column-name is the name of the column
  • newValue is the value to be updated in column_name
  • Filter-condition is the condition to filter out the record from the table.

Let’s understand the above update syntax by taking an example.

Example of Update statement in MySQL

We have employee table who has following 2 records.

SELECT * FROM employee;

+-------+-----------+----------+----------------+
| EMPID | FIRSTNAME | LASTNAME | DESIGNATION    |
+-------+-----------+----------+----------------+
|   100 | Ronny     | Waugh    | Accountant     |
|   101 | Jack      | Low      | Accountant |
+-------+-----------+----------+----------------+       

Let’s update record 101 with an update query in MySQL.

UPDATE employee SET designation="Sr. Accountant" WHERE empid=101;

In this example, we have updated the designation to Sr. Accountant of the employee table having empid=101

SELECT * FROM employee;
+-------+-----------+----------+----------------+
| EMPID | FIRSTNAME | LASTNAME | DESIGNATION    |
+-------+-----------+----------+----------------+
|   100 | Ronny     | Waugh    | Accountant     |
|   101 | Jack      | Low      | Sr. Accountant |
+-------+-----------+----------+----------------+              
Scroll to Top