mysql findinset
The FIND_IN_SET function in MySQL is used to find the position of a string within a comma-separated list of strings. The syntax for using FIND_IN_SET is as follows:
FIND_IN_SET(search_string, comma_separated_list)
Here, search_string is the string that you want to search for, and comma_separated_list is the list of strings in which you want to search.
The function returns the position of the search string within the list, or 0 if the string is not found. Note that the positions are 1-based.
Here is an example of how to use FIND_IN_SET:
SELECT FIND_IN_SET('apple', 'apple,banana,orange') as position;
This query will return the position of 'apple' within the list 'apple,banana,orange'. In this case, the result will be 1.
You can also use FIND_IN_SET in a WHERE clause to filter rows based on the presence of a string in a list. For example:
SELECT * FROM fruits WHERE FIND_IN_SET('apple', fruits_list) > 0;
This query will return all rows from the 'fruits' table where 'apple' is present in the 'fruits_list' column
原文地址: https://www.cveoy.top/t/topic/hZ25 著作权归作者所有。请勿转载和采集!