
- 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
Update only a single column value in MySQL
Let us first create a table −
mysql> create table DemoTable1605 -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(20), -> StudentCountryName varchar(20) -> ); Query OK, 0 rows affected (0.48 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1605(StudentName,StudentCountryName) values('Adam','AUS'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable1605(StudentName,StudentCountryName) values('John','US'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable1605(StudentName,StudentCountryName) values('Bob','UK'); Query OK, 1 row affected (0.11 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1605;
This will produce the following output −
+-----------+-------------+--------------------+ | StudentId | StudentName | StudentCountryName | +-----------+-------------+--------------------+ | 1 | Adam | AUS | | 2 | John | US | | 3 | Bob | UK | +-----------+-------------+--------------------+ 3 rows in set (0.00 sec)
Following is the query to update only a single column value in MySQL −
mysql> update DemoTable1605 set StudentName='Chris' where StudentCountryName='UK'; Query OK, 1 row affected (0.09 sec) Rows matched: 1 Changed: 1 Warnings: 0
Let us check the table records once again −
mysql> select * from DemoTable1605;
This will produce the following output −
+-----------+-------------+--------------------+ | StudentId | StudentName | StudentCountryName | +-----------+-------------+--------------------+ | 1 | Adam | AUS | | 2 | John | US | | 3 | Chris | UK | +-----------+-------------+--------------------+ 3 rows in set (0.00 sec)
- Related Articles
- Updating only a single column value in MySQL?
- Update multiple rows in a single column in MySQL?
- Update only a single column in a MySQL table and increment on the basis of a condition
- A single MySQL query to update only specific records in a range without updating the entire column
- How to update all the entries except a single value in a particular column using MySQL?
- Best way to update a single column in a MySQL table?
- Update only a single document in MongoDB
- MySQL query to update only a single field in place of NULL
- Update only a single value from a MySQL table where select from same table ordered in descending order?
- How to cast and update a numeric value from string column only where applicable in MySQL?
- Update a column value, replacing part of a string in MySQL?
- Subtracting a number from a single MySQL column value?
- Get only a single value from a specific MySQL row?
- Replace only a specific value from a column in MySQL
- Insertion in a MySQL table with only a single column set as auto_increment?

Advertisements