
- 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
Change One Cell's Data in MySQL?
Update only one cell’s data with the help of UPDATE command. The syntax is as follows −
UPDATE yourTableName yourColumnName=yourNewValue where yourColumnName=yourOldValue;
To understand the above concept, let us first create a table. The query to create a table is as follows −
mysql> create table changeCellsData -> ( -> Id int, -> Name varchar(100), -> Age int -> ); Query OK, 0 rows affected (0.81 sec)
Insert some records in the table using insert command. The query is as follows −
mysql> insert into changeCellsData values(101,'Mike',23); Query OK, 1 row affected (0.12 sec) mysql> insert into changeCellsData values(103,'Bob',25); Query OK, 1 row affected (0.18 sec) mysql> insert into changeCellsData values(105,'Sam',27); Query OK, 1 row affected (0.12 sec) mysql> insert into changeCellsData values(106,'Carol',21); Query OK, 1 row affected (0.24 sec)
Display all records from the table using select statement. The query is as follows −
mysql> select *from changeCellsData;
Output
+------+-------+------+ | Id | Name | Age | +------+-------+------+ | 101 | Mike | 23 | | 103 | Bob | 25 | | 105 | Sam | 27 | | 106 | Carol | 21 | +------+-------+------+ 4 rows in set (0.00 sec)
Here is the query to change cell data using update and set command. We are updating the last record of column “Id”.
The query is as follows −
mysql> update changeCellsData set Id=107 where Id=106; Query OK, 1 row affected (0.19 sec) Rows matched: 1 Changed: 1 Warnings: 0
Now you can check the cell data has been changed or not using select command. The query is as follows −
mysql> select *from changeCellsData;
Output
+------+-------+------+ | Id | Name | Age | +------+-------+------+ | 101 | Mike | 23 | | 103 | Bob | 25 | | 105 | Sam | 27 | | 107 | Carol | 21 | +------+-------+------+ 4 rows in set (0.00 sec)
- Related Articles
- Update data in one table from data in another table in MySQL?
- Change Data Type for one or more columns in Pandas Dataframe
- Change Data Type for one or more columns in Pandas Dataframe
- Insert data from one table to another in MySQL?
- Insert data from one schema to another in MySQL?
- What should one use CHAR data type or VARCHAR data type in MySQL?
- How can we change the data type of the column in MySQL table?
- How to change the order of one column data frame and get the output in data frame format in R?
- Can we GROUP BY one column and select all data in MySQL?
- Which one should I use? The datetime or timestamp data type in MySQL?
- Select MySQL rows where column contains same data in more than one record?
- Change max_heap_table_size value in MySQL?
- How to change the column position of MySQL table without losing column data?
- How To Change The MySQL Data Directory to Another Location on Ubuntu 16.04
- Simplest way to copy data from one table to another new table in MySQL?

Advertisements