
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Update All Rows by Prefixing a Line in MySQL
For this, use the CONCAT() function. Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Subject varchar(200) ); Query OK, 0 rows affected (1.36 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(Subject) values('MySQL'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(Subject) values('MongoDB'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(Subject) values('Java'); Query OK, 1 row affected (0.12 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+----+---------+ | Id | Subject | +----+---------+ | 1 | MySQL | | 2 | MongoDB | | 3 | Java | +----+---------+ 3 rows in set (0.00 sec)
Here is the query to update all rows by prefixing a line −
mysql> update DemoTable set Subject=concat("My Favourite Subject is ",Subject); Query OK, 3 rows affected (0.12 sec) Rows matched: 3 Changed: 3 Warnings: 0
Let us check the all records once again from table −
mysql> select *from DemoTable;
Output
+----+---------------------------------+ | Id | Subject | +----+---------------------------------+ | 1 | My Favourite Subject is MySQL | | 2 | My Favourite Subject is MongoDB | | 3 | My Favourite Subject is Java | +----+---------------------------------+ 3 rows in set (0.00 sec)
Advertisements