Jump to: navigation, search

Mysql FIELD

From w3cyberlearnings

Contents

MySQL x1 Function

This function returns the index of Find in the Str1, Str2, Str3...

Syntax x1

  • Find: String to check in Str1, Str2, Str3..
  • Str1: String 1
  • Str2: String 2
  • Str3: String 3
  • Str4: String 4
FIELD(find,Str1, Str2, Str3, Str4,...);

Note

  • Return 0/Null when nothing has found.
  • Return the string index, when it is found. (Index starts from 1)

Example 1

  • Found string 'goes' in index 4.
mysql> SELECT FIELD('goes','mark','john','gone','goes','lost');
+--------------------------------------------------+
| FIELD('goes','mark','john','gone','goes','lost') |
+--------------------------------------------------+
|                                                4 |
+--------------------------------------------------+
1 row in set (0.00 sec)

Example 2

mysql> SELECT FIELD('gone','mark','john','gone','goes','lost');
+--------------------------------------------------+
| FIELD('gone','mark','john','gone','goes','lost') |
+--------------------------------------------------+
|                                                3 |
+--------------------------------------------------+
1 row in set (0.00 sec)

Related Links


Navigation
Web
SQL
MISC
References