Name

FIELD( )

Synopsis

FIELD(string, string[, ...])

This function searches for the first string given in the list of other strings and returns the numeric position of the first argument that matches. The first element is 1 among the arguments being searched. If the search string is not found or is NULL, 0 is returned.

SELECT FIELD('test', 'test','one','two','three')
       AS 'FIELD( ) Test';
+--------------+
| FIELD( ) Test |
+--------------+
|            1 |
+--------------+

Notice that each string is a separate argument. To provide one string containing a comma-separated list instead, use FIND_IN_SET( ).

Get MySQL in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.