MySQL ELT() Function

In MySQL, the ELT() function returns string parameters at the specified position from all parameters.

ELT() Syntax

Here is the syntax of MySQL ELT() function:

ELT(pos, str1, str2, ...)

Parameters

pos
Required. The number used to specify the position.
str1, str2, ...
Required. String parameter list.

Return value

The ELT(pos, str1, str2, ...) function returns string parameters at the specified position from all parameters. If pos is 1, the ELT() function returns str1; If pos is 2, the ELT() function returns str2; And so on.

ELT() Examples

Here are some examples of MySQL ELT() function.

SELECT
    ELT(1, 'Aa', 'Bb', 'Cc'),
    ELT(3, 'Aa', 'Bb', 'Cc'),
    ELT(0, 'Aa', 'Bb', 'Cc'),
    ELT(4, 'Aa', 'Bb', 'Cc')\G
ELT(1, 'Aa', 'Bb', 'Cc'): Aa
ELT(3, 'Aa', 'Bb', 'Cc'): Cc
ELT(0, 'Aa', 'Bb', 'Cc'): NULL
ELT(4, 'Aa', 'Bb', 'Cc'): NULL