MySQL ELT Function

MySQL ELT is one of the String Functions, which returns the string expression or str value at the index position specified in the first argument. The basic syntax of it is as shown below:

SELECT ELT (Value, Str1, Str2,....,StrN)
FROM Source

The above string ELT returns Str1 to StrN based on the index position given at the Value argument. For example, (2, ‘Hi’, ‘Hello’) return Hello as the output.

MySQL ELT Function Example

This method returns the string at the specified position. The following Function query shows you multiple ways to use this.

SELECT ELT(1, 'Learn', 'MySQL', 'Tutorial', 'at', '');

SELECT ELT(3, 'Learn', 'MySQL', 'Tutorial', 'at', '');

SELECT ELT(5, 'Learn', 'MySQL', 'Tutorial', 'at', '');

SELECT ELT(5, 'Learn', 'MySQL', 'Tutorial');

SELECT ELT(-2, 'Learn', 'MySQL', 'Tutorial');
MySQL ELT Function Example 1

Let me show you what happens if we specify NULL values as the MySQL arguments.

SELECT ELT('2', 'Learn', 'MySQL', 'Tutorial');

SELECT ELT(2, 'Learn', NULL, 'MySQL', 'Tutorial');

SELECT ELT(NULL, 'Learn', NULL, 'MySQL', 'Tutorial');
ELT Example 2