In MySQL, you can use the ELT()
function to return a list item at a given position in the list.
The syntax goes like this:
ELT(N,str1,str2,str3,...)
Where N
is the position of the item you want to return, and str1,str2,str3,...
is the list.
Example
Here’s an example:
SELECT ELT(3, 'Marge', 'Homer', 'Bart') AS 'Who is at 3?';
Result:
+--------------+ | Who is at 3? | +--------------+ | Bart | +--------------+
In this case we specify that we want to return the 3rd item in the list (because the first argument is 3
) . And in this case the list is 'Marge', 'Homer', 'Bart'
, so the 3rd item is Bart
. Continue reading