
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How can I change the value of an instance of a row in MySQL table?
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)
- Related Articles
- How can I change the name of an existing column from a MySQL table?
- How can I change the storage engine of a MySQL table?
- How can we change the name of a MySQL table?
- How can I see the CREATE TABLE statement of an existing MySQL table?
- How can I customize value, instead of NULL, of a row by using MySQL IF() function?
- How can I calculate the total value of products from my MySQL product table?
- How can we change the data type of the column in MySQL table?
- How can I update a field in a MySQL database table by adding a value in the second table with a value from the first table?
- How can I remove a value from an enum in MySQL?
- How can I drop an existing column from a MySQL table?
- How can I loop through all rows of a table in MySQL?
- How can we delete a single row from a MySQL table?
- How can we insert a new row into a MySQL table?
- How can I change the default sort order of MySQL tables?
- How can we extract a substring from the value of a column in MySQL table?

Advertisements