ELT( )

This MySQL function returns the index element from the list of strings given, where the list is numbered starting with 1.

Syntax

Below is the syntax for this command. Text within square brackets (i.e, [ and ] ) are optional. Choices are separated by bars (i.e, | ). Ellipses preceded by a comma indicates a repeating pattern. Ellipses before or after syntax are used to highlight a relevant except from the larger syntax. Text displayed in italic letters represent text that should be replaced with the specific names related to the database (e.g., column with the name of the column).

ELT(index, string, ...)

Explanation

This function returns the index element from the list of strings given, where the list is numbered starting with 1. If the number given is less than 1 or if the number of elements is less than the number given, this statement returns NULL.

Examples

SELECT student_id,
CONCAT(name_first, SPACE(1), name_last)
   AS Name,
ELT(primary_phone, phone_dorm, phone_home, phone_work)
   AS Telephone
FROM students;

In this SQL statement, we're using the value of the primary_phone column to provide the index for ELT( ). This column is an ENUM column that records which of the three telephone columns is the student's primary telephone number. The function will return the value for the column selected based on the index. As a result, the SQL statement will give a list of students and their primary telephone numbers.