CONCAT দিয়ে এক্সিস্টিং ভ্যালুর সাথে টেক্সট যোগ
একটি কলামের বিদ্যমান ভ্যালুর সাথে নতুন টেক্সট কনক্যাটেনেট করতে UPDATE ... SET col = CONCAT(col, 'new text') ব্যবহার করুন।
সিনট্যাক্স
UPDATE yourTable SET yourColumn = CONCAT(yourColumn, 'text to append') WHERE condition;
উদাহরণ
টেবিল তৈরি
mysql> create table addToExistingValueDemo (
-> Instructor_Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
-> Instructor_Name varchar(30),
-> Instructor_TechnicalSubject text
-> );
Query OK, 0 rows affected (0.54 sec)
ডেটা ইনসার্ট
mysql> insert into addToExistingValueDemo(Instructor_Name,Instructor_TechnicalSubject) values('John','C,C++');
Query OK, 1 row affected (0.15 sec)
mysql> insert into addToExistingValueDemo(Instructor_Name,Instructor_TechnicalSubject) values('Carol','Java,Python');
Query OK, 1 row affected (0.18 sec)
mysql> insert into addToExistingValueDemo(Instructor_Name,Instructor_TechnicalSubject) values('Bob','MySQL,SQL Server');
Query OK, 1 row affected (0.15 sec)
mysql> insert into addToExistingValueDemo(Instructor_Name,Instructor_TechnicalSubject) values('David','DataStructure');
Query OK, 1 row affected (0.18 sec)
আপডেট করার আগে
mysql> SELECT * FROM addToExistingValueDemo;
আউটপুট
+---------------+-----------------+-----------------------------+ | Instructor_Id | Instructor_Name | Instructor_TechnicalSubject | +---------------+-----------------+-----------------------------+ | 1 | John | C,C++ | | 2 | Carol | Java,Python | | 3 | Bob | MySQL,SQL Server | | 4 | David | DataStructure | +---------------+-----------------+-----------------------------+
Instructor_Id=4 এর জন্য টেক্সট যোগ
mysql> UPDATE addToExistingValueDemo
-> SET Instructor_TechnicalSubject = CONCAT(Instructor_TechnicalSubject, ', Introduction To Algorithm')
-> WHERE Instructor_Id = 4;
Query OK, 1 row affected (0.10 sec)
আপডেটের পর
mysql> SELECT * FROM addToExistingValueDemo;
আউটপুট
+---------------+-----------------+------------------------------------------+ | Instructor_Id | Instructor_Name | Instructor_TechnicalSubject | +---------------+-----------------+------------------------------------------+ | 1 | John | C,C++ | | 2 | Carol | Java,Python | | 3 | Bob | MySQL,SQL Server | | 4 | David | DataStructure, Introduction To Algorithm | +---------------+-----------------+------------------------------------------+
নোট: CONCAT() আর্গুমেন্টের যেকোনোটি NULL হলে ফলাফল NULL হয়। NULL হ্যান্ডল করতে COALESCE(col, '') বা CONCAT_WS() ব্যবহার করুন।