MySQL 如何使用MySQL的FIND_IN_SET()函数从表中获取特定的记录作为结果集?
我们可以通过将特定字符串和列名称作为FIND_IN_SET()函数的参数来获取记录的结果集。我们还需要在FIND_IN_SET()函数中使用WHERE子句。为了理解它,我们将使用下面从表“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()函数获取以字符串“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)
阅读更多:MySQL 教程