How can we use FIND_IN_SET() function with MySQL WHERE clause?

MySQLMySQLi Database

When we use FIND_IN_SET() function in WHERE clause then it searches the search string within the given string as specified in the argument and retrieves all the columns from concerned rows. Following is an example to demonstrate it −


In this example, we are getting the columns from ‘Student’ table where the rows have the value of name as ‘Gaurav’. Here the FIND_IN_SET() function will search the search string ‘Gaurav’ from the values of column ‘Name’.

mysql> Select Id, Name, Address, Subject from student WHERE FIND_IN_SET('Gaurav',Name);

| Id   | Name   | Address | Subject   |
| 1    | Gaurav | Delhi   | Computers |
| 20   | Gaurav | Jaipur  | Computers |

2 rows in set (0.20 sec)
Updated on 20-Jun-2020 08:45:16