How can MySQL FIND_IN_SET() function be used to get the particular record(s) from the table as a result set?

MySQLMySQLi Database

We can get the record(s) as a result set by providing the particular string and name of the column as arguments of FIND_IN_SET() function. We also need to use WHERE clause with FIND_IN_SET() function. To understand it, we are using the data, given as below, from table ‘student_info’:

mysql> Select * from student_info;
+------+---------+----------+------------+
| id   | Name    | Address  | Subject    |
+------+---------+----------+------------+
| 101  | YashPal | Amritsar | History    |
| 105  | Gaurav  | Jaipur   | Literature |
| 125  | Raman  | Shimla    | Computers  |
+------+---------+----------+------------+
3 rows in set (0.00 sec)

Now, following query will use FIND_IN_SET() function to get particular records as result set having the name of the student as ‘Raman’:

mysql> Select Id, Name, Subject from Student_info Where FIND_IN_SET('Raman',Name);
+------+-------+-----------+
| Id   | Name  | Subject   |
+------+-------+-----------+
| 125  | Raman | Computers |
+------+-------+-----------+
1 row in set (0.00 sec)
raja
Published on 21-Feb-2018 09:09:39
Advertisements