MySQL ELT Function

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

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

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

MySQL ELT Example 1

The String ELT function in MySQL returns the string at the specified position. The following ELT String Function query shows you multiple ways to use this ELT function.

-- MySQL String ELT Function Example
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 happen if we specify NULL values as the MySQL arguments.

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

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

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