- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
MySQL query to fecth the domain name from email-id?
Use SUBSTRING_INDEX() for this. Let us first create a table −
mysql> create table DemoTable -> ( -> UserMailId varchar(100) -> ); Query OK, 0 rows affected (0.68 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('John@gmail.com'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('Carol94844@yahoo.com'); Query OK, 1 row affected (0.25 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+----------------------+ | UserMailId | +----------------------+ | John@gmail.com | | Carol94844@yahoo.com | +----------------------+ 2 rows in set (0.00 sec)
Following is the query to fetch the domain name −
mysql> select substring_index(UserMailId,'@',-1) as RightSideValue from DemoTable;
Output
This will produce the following output −
+----------------+ | RightSideValue | +----------------+ | gmail.com | | yahoo.com | +----------------+ 2 rows in set (0.00 sec)
Advertisements
To Continue Learning Please Login
Login with Google