
- 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
Updating only a single column value in MySQL?
Let us first create a table −
mysql> create table DemoTable770 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Value int ); Query OK, 0 rows affected (0.65 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable770(Value) values(10); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable770(Value) values(90); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable770(Value) values(160); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable770(Value) values(450); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable770(Value) values(560); Query OK, 1 row affected (0.21 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable770;
This will produce the following output -
+----+-------+ | Id | Value | +----+-------+ | 1 | 10 | | 2 | 90 | | 3 | 160 | | 4 | 450 | | 5 | 560 | +----+-------+ 5 rows in set (0.00 sec)
Following is the query to update only a single column value −
mysql> update DemoTable770 set Value=Value+150 where Id=4; Query OK, 1 row affected (0.52 sec) Rows matched: 1 Changed: 1 Warnings: 0
Let us check the description of the view −
mysql> select *from DemoTable770;
This will produce the following output -
+----+-------+ | Id | Value | +----+-------+ | 1 | 10 | | 2 | 90 | | 3 | 160 | | 4 | 600 | | 5 | 560 | +----+-------+ 5 rows in set (0.00 sec)
- Related Articles
- Update only a single column value in MySQL
- A single MySQL query to update only specific records in a range without updating the entire column
- Updating boolean value 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?
- Updating a MySQL table row column by appending a value from user defined variable?
- MySQL select only a single value from 5 similar values?
- Decrement only a single value in MongoDB?
- How to insert only a single column into a MySQL table with Java?
- Updating a MySQL column that contains dot (.) in its name?
- MySQL query to remove a value with only numbers in a column
- Updating default value of new column in SAP system
- How to display a single quote text as a column value in MySQL?

Advertisements