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.

  • N : It is an integer and it is the index of the string to be retrieved.
  • string1, string2, string3 : List of strings from which we want retrieve.

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
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.