SQL Server has a CHOOSE()
function that returns a list item at a given position. MySQL also has an equivalent function, but with a different name.
In MySQL, the ELT()
function does essentially the same thing that CHOOSE()
does in SQL Server. It allows you to find the list item at a given position within the list.
Example
Here’s an example:
SELECT ELT(3, 'Cat', 'Dog', 'Horse') AS 'Result';
Result:
+--------+ | Result | +--------+ | Horse | +--------+
You can also use numbers, and you can return values from a database and match them with your own list.
The SQL Server Version
Here’s how you’d do the above example in SQL Server:
SELECT CHOOSE(3, 'Cat', 'Dog', 'Horse') AS 'Result';
Result:
Result ------ Horse
So the only difference is the function name.
For more examples, see How to Find a List Item at a Specified Position in MySQL.