我们可以通过提供特定的字符串和列名作为FIND_IN_SET()函数的参数来获取记录作为结果集。我们还需要将WHERE子句与FIND_IN_SET()函数一起使用。为了理解这一点,我们使用来自表'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)
现在,以下查询将使用FIND_IN_SET()函数获取特定记录作为结果集,该记录的学生姓名为“拉曼”:
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)