Curriculum
Course: SQL
Login

Curriculum

SQL

SQL References

0/80

MySQL Functions

0/139

SQL Server Functions

0/84

SQL Quick Ref

0/1
Text lesson

FIELD

Example

Retrieve the index position of “q” within the given list of strings.

SELECT FIELD(“q”, “s”, “q”, “l”);  

Definition and Usage

The FIELD() function retrieves the index position of a value within a list of values, performing a case-insensitive search.

Note: If the specified value is not found or is NULL, the function returns 0.

Syntax

FIELD(value, val1, val2, val3, …)

Parameter Values

Parameter

Description

value

Necessary: The value to be searched for within the list.

val1val2val3, ….

Necessary: The list of values to be searched within.

Technical Details

Works in: From MySQL 4.0

More Examples

Example

Retrieve the index position of “c” within the given list of strings.

SELECT FIELD(“c”, “a”, “b”);  

Example

Retrieve the index position of “Q” within the provided list of strings.

SELECT FIELD(“Q”, “s”, “q”, “l”);  

Example

Retrieve the index position of the number 5 within the given list of numbers.

SELECT FIELD(5, 0, 1, 2, 3, 4, 5);