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
Release: 2023-09-22 14:33:04
forward
676 people have browsed it

如何使用 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)
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template