CONCAT() ফাংশন দিয়ে স্ট্রিং জোড়া
SELECT ক্লজে একাধিক কলাম বা লিটারেল স্ট্রিং একসাথে জোড়াতে CONCAT() ব্যবহার করুন।
সিনট্যাক্স
SELECT CONCAT(col1, ' text ', col2, ' text') AS alias FROM yourTable;
উদাহরণ
টেবিল তৈরি
mysql> create table ConcatenatingDemo (
-> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
-> UserName varchar(20),
-> UserCountryName varchar(20)
-> );
Query OK, 0 rows affected (0.82 sec)
ডেটা ইনসার্ট
mysql> insert into ConcatenatingDemo(UserName,UserCountryName) values('John','US');
Query OK, 1 row affected (0.14 sec)
mysql> insert into ConcatenatingDemo(UserName,UserCountryName) values('Carol','UK');
Query OK, 1 row affected (0.13 sec)
mysql> insert into ConcatenatingDemo(UserName,UserCountryName) values('Bob','AUS');
Query OK, 1 row affected (0.15 sec)
mysql> insert into ConcatenatingDemo(UserName,UserCountryName) values('David','US');
Query OK, 1 row affected (0.29 sec)
সকল রেকর্ড
mysql> SELECT * FROM ConcatenatingDemo;
আউটপুট
+--------+----------+-----------------+ | UserId | UserName | UserCountryName | +--------+----------+-----------------+ | 1 | John | US | | 2 | Carol | UK | | 3 | Bob | AUS | | 4 | David | US | +--------+----------+-----------------+
CONCAT দিয়ে টেক্সট যোগ
mysql> SELECT CONCAT(UserName, ' belongs to ( ', UserCountryName, ' )') AS AddingTextDemo FROM ConcatenatingDemo;
আউটপুট
+-------------------------+ | AddingTextDemo | +-------------------------+ | John belongs to ( US ) | | Carol belongs to ( UK ) | | Bob belongs to ( AUS ) | | David belongs to ( US ) | +-------------------------+
নোট: CONCAT()-এ যেকোনো আর্গুমেন্ট NULL হলে ফলাফল NULL হয়। NULL সেফ কনক্যাটেনেশনের জন্য CONCAT_WS(',', col1, col2) (separator সহ) বা COALESCE(col, '') ব্যবহার করুন।