Select*fromstudent_info;+------+---------+-------- --+----------------+|id |Name |Address |S"/> Select*fromstudent_info;+------+---------+-------- --+----------------+|id |Name |Address |S">

Home >Database >Mysql Tutorial >How to get specific records from a table as a result set using the MySQL FIND_IN_SET() function?

How to get specific records from a table as a result set using the MySQL FIND_IN_SET() function?

WBOY
WBOYforward
2023-09-22 14:33:04684browse

如何使用 MySQL FIND_IN_SET() 函数从表中获取特定记录作为结果集?

We can get records as a result set by providing specific string and column names as parameters to the FIND_IN_SET() function. We also need to use the WHERE clause with the FIND_IN_SET() function. To understand it, we use the data from table "student_info" as shown below:

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, the following query will get specific records as result set using FIND_IN_SET() function where student name is "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)

The above is the detailed content of How to get specific records from a table as a result set using the MySQL FIND_IN_SET() function?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete