
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to replace a part of the string (domain name after @) using MySQL?
Let us first create a table −
mysql> create table DemoTable -> ( -> EmailId varchar(30) -> ); Query OK, 0 rows affected (0.53 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('John123@example.com'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('John123@gmail.com'); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable values('John123@yahoo.com'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('John123@example.com'); Query OK, 1 row affected (0.10 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+---------------------+ | EmailId | +---------------------+ | John123@example.com | | John123@gmail.com | | John123@yahoo.com | | John123@example.com | +---------------------+ 4 rows in set (0.00 sec)
Here is the query to replace a part of the string −
mysql> update DemoTable -> set EmailId=replace(EmailId,'John123@example.com','John123@gmail.com'); Query OK, 2 rows affected (0.16 sec) Rows matched: 4 Changed: 2 Warnings: 0
Let us check the table records once again −
mysql> select *from DemoTable;
This will produce the following output −
+-------------------+ | EmailId | +-------------------+ | John123@gmail.com | | John123@gmail.com | | John123@yahoo.com | | John123@gmail.com | +-------------------+ 4 rows in set (0.00 sec)
- Related Questions & Answers
- MySQL query to replace part of string before dot
- Replace part of string in MySQL table column?
- MySQL query to change a string by displaying only the part of string after underscore?
- Replace part of a string with another string in C++
- How to get a part of string after a specified character in JavaScript?
- Fetch domain name by passing name in MySQL?
- Find and replace a part of URL records in MySQL?
- How to cut part of a string with a MySQL query?
- Does JavaScript have a method to replace part of a string without creating a new string?
- MySQL query to fecth the domain name from email-id?
- MySQL query to replace a string after the last / in a column with directory links?
- How to select domain name from email address in MySQL?
- How to order by certain part of a string in MySQL?
- Split the left part of a string by a separator string in MySQL?
- How can we replace specific part of String and StringBuffer in Java?
Advertisements