ELT

ELT(n, str1, str2, …)

Returns the nth value from the list str1, str2, … If n is less than 1 or greater than the number of values, it returns NULL. It is the opposite of the FIELD() function.

Parameters

  • n – the position of the returned value, from 1.
  • str1, str2, … – the list of values.

Examples

Examples with the customers, products and orders tables use the sample database from the SQL basics series.

SELECT ELT(2, 'new', 'paid', 'shipped') AS status, ELT(5, 'a', 'b') AS out_of_range;
+--------+--------------+
| status | out_of_range |
+--------+--------------+
| paid   | NULL         |
+--------+--------------+

A short day name (DAYOFWEEK returns 1 = Sunday):

SELECT order_date, ELT(DAYOFWEEK(order_date), 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat') AS day
FROM orders
GROUP BY order_date
ORDER BY order_date
LIMIT 4;
+------------+-----+
| order_date | day |
+------------+-----+
| 2026-01-05 | Mon |
| 2026-01-12 | Mon |
| 2026-02-03 | Tue |
| 2026-02-20 | Fri |
+------------+-----+

Things to watch out for

  • A number out of range returns NULL, not an error.
  • MySQL and MariaDB can return day and month names in other languages through the setting lc_time_names = 'de_DE' and the DAYNAME() and MONTHNAME() functions.

Related:
FIELD()
DAYOFWEEK()
MONTHNAME()