প্রথমে একটি টেবিল তৈরি করি:
mysql> create table DemoTable1465 (
-> Name varchar(40)
-> );
Query OK, 0 rows affected (0.54 sec)
রেকর্ড ইনসার্ট করি:
mysql> insert into DemoTable1465 values('Chris Brown');
Query OK, 1 row affected (0.10 sec)
mysql> insert into DemoTable1465 values('David Miller');
Query OK, 1 row affected (0.26 sec)
mysql> insert into DemoTable1465 values('John Doe');
Query OK, 1 row affected (0.14 sec)
সব রেকর্ড দেখি:
mysql> select * from DemoTable1465;
আউটপুট:
+--------------+ | Name | +--------------+ | Chris Brown | | David Miller | | John Doe | +--------------+ 3 rows in set (0.00 sec)
SUBSTRING_INDEX() ব্যবহার করে প্রথম ও শেষ নাম আলাদা করার কোয়েরি:
mysql> select
-> substring_index(substring_index(Name, ' ', 1), ' ', -1) as StudentFirstName,
-> substring_index(substring_index(Name, ' ', 3), ' ', -1) AS StudentLastName
-> from DemoTable1465;
আউটপুট:
+------------------+-----------------+ | StudentFirstName | StudentLastName | +------------------+-----------------+ | Chris | Brown | | David | Miller | | John | Doe | +------------------+-----------------+ 3 rows in set (0.00 sec)
ব্যাখ্যা: SUBSTRING_INDEX(str, delim, count) - count পজিটিভ হলে বাম থেকে, নেগেটিভ হলে ডান থেকে count-তম ডেলিমিটার পর্যন্ত রিটার্ন করে। নেস্টেড ব্যবহার করে নির্দিষ্ট ওয়ার্ড বের করা হয়েছে।