MySQL: FIND_IN_SET Function

  • Post author:
  • Post category:MySQL
  • Post comments:1 Comment
MySQL FIELD_IN_SET Function

In this guide, we will explain how to use the MySQL FIND_IN_SET function with syntax and examples.

Description

The MySQL FIND_IN_SET function returns the position of a string in a comma-delimited string-list.

Syntax

The syntax for the FIND_IN_SET function in MySQL is:

FIND_IN_SET( string, string_list )

Parameters or Arguments

stringThe string to find.string_listThe list of string values separated by commas that is to be searched.

Note

  • If string is not found in string_list, the FIND_IN_SET function will return 0.
  • If string is NULL, the FIND_IN_SET function will return NULL.
  • If string_list is an empty string, the FIND_IN_SET function will return 0.
  • If string_list is NULL, the FIND_IN_SET function will return NULL.

Applies To

The FIND_IN_SET function can be used in the following versions of MySQL:

  • MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23

Example

Let’s look at some MySQL FIND_IN_SET function examples and explore how to use the FIND_IN_SET function in MySQL.

For example:

mysql> SELECT FIND_IN_SET('b', 'a,b,c,d,e,f');
Result: 2

mysql> SELECT FIND_IN_SET('B', 'a,b,c,d,e,f');
Result: 2

mysql> SELECT FIND_IN_SET('f', 'a,b,c,d,e,f');
Result: 6

mysql> SELECT FIND_IN_SET(2,'1,2,3');
Result: 2

mysql> SELECT FIND_IN_SET('g', 'a,b,c,d,e,f');
Result: 0

mysql> SELECT FIND_IN_SET('g', '');
Result: 0

mysql> SELECT FIND_IN_SET(null, 'a,b,c');
Result: NULL

mysql> SELECT FIND_IN_SET('a', null);
Result: NULL

Next Topic : Click Here

This Post Has One Comment

Leave a Reply