Tutorials References Exercises Videos Menu
Create Website Get Certified Upgrade

SQL Tutorial

SQL HOME SQL Intro SQL Syntax SQL Select SQL Select Distinct SQL Where SQL And, Or, Not SQL Order By SQL Insert Into SQL Null Values SQL Update SQL Delete SQL Select Top SQL Min and Max SQL Count, Avg, Sum SQL Like SQL Wildcards SQL In SQL Between SQL Aliases SQL Joins SQL Inner Join SQL Left Join SQL Right Join SQL Full Join SQL Self Join SQL Union SQL Group By SQL Having SQL Exists SQL Any, All SQL Select Into SQL Insert Into Select SQL Case SQL Null Functions SQL Stored Procedures SQL Comments SQL Operators

SQL Database

SQL Create DB SQL Drop DB SQL Backup DB SQL Create Table SQL Drop Table SQL Alter Table SQL Constraints SQL Not Null SQL Unique SQL Primary Key SQL Foreign Key SQL Check SQL Default SQL Index SQL Auto Increment SQL Dates SQL Views SQL Injection SQL Hosting SQL Data Types

SQL References

SQL Keywords MySQL Functions SQL Server Functions MS Access Functions SQL Quick Ref

SQL Examples

SQL Examples SQL Quiz SQL Exercises SQL Certificate

MySQL FIELD() Function

Example

Return the index position of  "q" in the string list:

SELECT FIELD("q", "s", "q", "l");
Try it Yourself »

Definition and Usage

The FIELD() function returns the index position of a value in a list of values.

This function performs a case-insensitive search.

Note: If the specified value is not found in the list of values, this function will return 0. If value is NULL, this function will return 0.

Syntax

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

Parameter Values

Parameter Description
value Required. The value to search for in the list
val1, val2, val3, .... Required. The list of values to search

Technical Details

Works in: From MySQL 4.0

More Examples

Example

Return the index position of "c" in the string list:

SELECT FIELD("c", "a", "b");
Try it Yourself »

Example

Return the index position of "Q" in the string list:

SELECT FIELD("Q", "s", "q", "l");
Try it Yourself »

Example

Return the index position of 5 in the numeric list:

SELECT FIELD(5, 0, 1, 2, 3, 4, 5);
Try it Yourself »