MySQL FIND_IN_SET Function: Search for Strings in Comma-Separated Lists
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: \n\nFIND_IN_SET(search_string, comma_separated_list)\n\nHere, 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.\n\nThe 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.\n\nHere is an example of how to use FIND_IN_SET:\n\nSELECT FIND_IN_SET('apple', 'apple,banana,orange') as position;\n\nThis query will return the position of 'apple' within the list 'apple,banana,orange'. In this case, the result will be 1.\n\nYou 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:\n\nSELECT * FROM fruits\nWHERE FIND_IN_SET('apple', fruits_list) > 0;\n\nThis query will return all rows from the 'fruits' table where 'apple' is present in the 'fruits_list' column.
原文地址: https://www.cveoy.top/t/topic/pI6S 著作权归作者所有。请勿转载和采集!