How can MySQL REPLACE() function be used with WHERE clause?


As we know that WHERE clause is used to put condition/s in MySQL query and MySQL returns result set based on those conditions. Similarly when we use REPLACE() function with WHERE clause, the result set will depend upon the conditions provided. Following is an example by using data from the ‘Student’ table in which REPLACE() function replaces the records of a column ‘Name’ in which the value of column ‘Subject’ is ‘Computers’.

Example

mysql> Select Name, REPLACE(Name, 'G','S') from student Where Subject = 'Computers';
+--------+------------------------+
| Name   | REPLACE(Name, 'G','S') |
+--------+------------------------+
| Gaurav | Saurav                 |
| Gaurav | Saurav                 |
+--------+------------------------+
2 rows in set (0.00 sec)

Sharon Christine
Sharon Christine

An investment in knowledge pays the best interest

Updated on: 22-Jun-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements