Open In App

ELT() Function in MySQL

In this article, we are going to cover ELT function with examples. In ELT function, number field will state that how many strings will be there.

ELT function in MySQL is used to returns the string which is at index number specified in the argument list. In this function there is number field and strings field.
Syntax :



 ELT(N, string1, string2, string3, string4, …)

Parameter :
This method accepts two parameter as mentioned above and described below.

Returns –
It returns a string at the specified index . It returns NULL, if there is no string at specified index N.



Example-1 :
Retrieving a string using ELT() function.

Select ELT(4, 'Learning', 'SQL', 'at', 'geeksforgeeks', 'is', 'fun') 
As Res_Str;

Output :

Res_Str
geeksforgeeks

Example-2 :
Retrieving a string using ELT() function.

Select ELT(1, 'Learning', 'SQL', 'at', 'geeksforgeeks', 'is', 'fun') 
As Res_Str;

Output :

Res_Str
Learning

Example-3 :
Retrieving a string using ELT() function when there is no string at specified index.

Select ELT(8, 'Learning', 'SQL', 'at', 'geeksforgeeks', 'is', 'fun') 
As Res_Str;

Output :

Res_Str
NULL
Article Tags :
SQL