How can I change the value of an instance of a row in MySQL table?

MySQLMySQLi Database

UPDATE command along with WHERE clause can be used to change the value of an instance of a row. Basically, MySQL will change the value on the basis of the condition given in the query. Following example can demonstrate it

Suppose we want to change the name from ‘Ram’ to ‘Mohit’ in the ‘testing’ table given below −

mysql> Select * from testing;

+----+---------+
| Id | Name    |
+----+---------+
| 1  | Harshit |
| 2  | Lovkesh |
| 3  | Ram     |
| 4  | Gaurav  |
+----+---------+

4 rows in set (0.00 sec)

Now by running the following query we can change the instance of row to ‘Mohit’ where it is ‘ram’.

mysql> UPDATE TESTING SET Name = 'MOHIT' WHERE name = ‘ram’;
Query OK, 1 row affected (0.13 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> Select * from testing;

+-----+---------+
| id1 | Name    |
+-----+---------+
| 1   | Harshit |
| 2   | Lovkesh |
| 3   | MOHIT   |
| 4   | Gaurav  |
+-----+---------+

4 rows in set (0.00 sec)
raja
Published on 19-Feb-2018 14:25:32
Advertisements