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

MySQLMySQLi Database

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)
raja
Published on 21-Feb-2018 09:12:09
Advertisements