MySQL এ নাম পাস করে ডোমেন নাম আনতে, আপনি substring_index() ব্যবহার করতে পারেন। আসুন প্রথমে একটি টেবিল তৈরি করি -
mysql> create table DemoTable ( UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, UserMailId varchar(200) ); Query OK, 0 rows affected (0.77 sec)
সন্নিবেশ কমান্ড -
ব্যবহার করে টেবিলে কিছু রেকর্ড সন্নিবেশ করুনmysql> insert into DemoTable(UserMailId) values('[email protected]'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(UserMailId) values('[email protected]'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable(UserMailId) values('[email protected]'); Query OK, 1 row affected (0.20 sec)
সিলেক্ট স্টেটমেন্ট -
ব্যবহার করে টেবিল থেকে সমস্ত রেকর্ড প্রদর্শন করুনmysql> select *from DemoTable;
এটি নিম্নলিখিত আউটপুট −
তৈরি করবে+--------+-----------------------+ | UserId | UserMailId | +--------+-----------------------+ | 1 | [email protected] | | 2 | [email protected] | | 3 | [email protected] | +--------+-----------------------+ 3 rows in set (0.00 sec)
MySQL এ নাম পাস করে ডোমেন নাম আনার জন্য নিচের প্রশ্নটি রয়েছে।
mysql> select UserId,UserMailId, substring_index(substring_index(UserMailId, '@', -1), '.', 1) AS `Domain_Name` from DemoTable;
এটি নিম্নলিখিত আউটপুট তৈরি করবে। এখানে, ডোমেইন নাম আনা হয়েছে −
+--------+-----------------------+-------------+ | UserId | UserMailId | Domain_Name | +--------+-----------------------+-------------+ | 1 | [email protected] | facebook | | 2 | [email protected] | yahoo | | 3 | [email protected] | gmail | +--------+-----------------------+-------------+ 3 rows in set (0.01 sec)