

SELECT FIND_IN_SET( 'a', NULL) Code language: SQL (Structured Query Language) ( sql ) The following statement also returns NULL because the second argument is NULL. SELECT FIND_IN_SET( NULL, 'x,y,z') Code language: SQL (Structured Query Language) ( sql ) The following statement returns NULL because the first argument is NULL. SELECT FIND_IN_SET( 'a', '') Code language: SQL (Structured Query Language) ( sql ) The following statement also returns 0 because the second argument is empty. SELECT FIND_IN_SET( 'a', 'x,y,z') Code language: SQL (Structured Query Language) ( sql ) The following statement returns 0 because a is not in the 'x,y,z' list. SELECT FIND_IN_SET( 'y', 'x,y,z') - 2 Code language: SQL (Structured Query Language) ( sql ) The following statement returns 2 because y has the second position in 'x,y,z' string. A) MySQL FIND_IN_SET() function simple examples Let’s take some examples to understand how the MySQL FIND_IN_SET works.


In addition, MySQL will use bit arithmetic optimization if the needle is a constant string and the haystack is a column of type SET. Note that the function will not work properly if the needle contains a comma (,).
#Mysql like vs substring how to#
Summary: in this tutorial, you will learn how to use the MySQL FIND_IN_SET() function to return the position of a string in a comma-separated list of strings.
