Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
MySQL query to replace a column value
Let us first create a table −
mysql> create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, Score int ); Query OK, 0 rows affected (0.45 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(Score) values(56); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable(Score) values(78); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable(Score) values(34); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable(Score) values(55); Query OK, 1 row affected (0.37 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-----------+-------+ | StudentId | Score | +-----------+-------+ | 1 | 56 | | 2 | 78 | | 3 | 34 | | 4 | 55 | +-----------+-------+ 4 rows in set (0.00 sec)
Following is the query to replace column value −
mysql> update DemoTable set Score=95 where StudentId=3; Query OK, 1 row affected (0.12 sec) Rows matched : 1 Changed : 1 Warnings : 0
Let us check the table records once again −
mysql> select *from DemoTable;
This will produce the following output −
+-----------+-------+ | StudentId | Score | +-----------+-------+ | 1 | 56 | | 2 | 78 | | 3 | 95 | | 4 | 55 | +-----------+-------+ 4 rows in set (0.00 sec)
Advertisements
