FIND_IN_SET() Function in MySql

mysql

How to use FIND_IN_SET() function in MySql . This tutorial explain how to use this in-built function to search for values within a comma separated values.

While working on some module i came across with MySql FIND_IN_SET() function. In my case i have to pull all the records whose status match with status list separated with comma are stored in table.


How to compare NULL value in MySql .

MySql Interview Questions .

Syntax of FIND_IN_SET() function

argument1 is a string.

argument2 is a string list separated by comma.

find_in_set() function returns the position of a string within second string. Returns zero when search string doesn’t exist in string list.

Note:

i) If string is not found in string_list, the FIND_IN_SET function will return 0.

ii) If string is NULL, the FIND_IN_SET function will return NULL.

iii) If string_list is an empty string, the FIND_IN_SET function will return 0.

iv) If string_list is NULL, the FIND_IN_SET function will return NULL.

How to find second highest salary in MySql.

How to install MySql workbench on Ubuntu.

Examples

Explanation of find_in_set() Function through Example

Create one table category and populate some values.

Table will look like this.

 

Let’s write query to find all the category_id and name whose cat_path contains value 4.

Three matching rows are fetched.

Difference between Inner Join and Left Join.

Tagged , . Bookmark the permalink.

About WebRewrite

I am technology lover who loves to keep updated with latest technology. My interest field is Web Development.