×

MySQL ELT() function

In this context, we will learn how we can use the MySQL ELT() function with proper syntax and good examples.

Introduction of MySQL ELT() function

In the ELT function, the number field will state how many strings there will be.

ELT function in MySQL is used to return the string, which is at the index number specified in the argument list. In this function, there is a number field and a strings field.

Syntax of the MySQL ELT() function

The syntax of the MySQL ELT() function is given as follows:

ELT(I, string1, string2, string3, string4, …);

Parameters or arguments used in MySQL ELT() function:

There are two parameters accepted by the ELT() function in MySQL, which are given as follows:

I: It is an integer, and it is the index of the string to be retrieved.

string1, string2, string3: these are the List of strings from which we want to retrieve the index.

Returns:

It will return a string at the specified index. When there is no string at the specified index I, then it will return NULL.

Application used for ELT() function:

The ELT() function can be used in the given below MySQL versions.:

  • MySQL 5.7
  • MySQL 5.6
  • MySQL 5.5
  • MySQL 5.1
  • MySQL 5.0
  • MySQL 4.1
  • MySQL 4.0
  • MySQL 3.23

Examples of MySQL ELT() function:

Now we will look into some MySQL ELT() function examples and will explore how we can use the ELT function in MySQL.

Example-1 :

Here, we will Retrieve a string using ELT() function in MySQL.

Select ELT(4, 'Learning', 'SQL', 'at', 'Javatpoint', 'is', 'fun') As Res_Str;

Output :

Res_Str
Javatpoint
1 row in set (0.00 sec)

Example-2 :

Here, we will Retrieve a string using ELT() function in MySQL.

Select ELT(1, 'Learning', 'SQL', 'at', 'Javatpoint', 'is', 'fun')
As Res_Str;

Output :

Res_Str
Learning
1 row in set (0.00 sec)

Example-3 :

Here, we will Retrieve a string using ELT() function when there is no string at the specified index.

Select ELT(8, 'Learning', 'SQL', 'at', 'Javatpoint', 'is', 'fun')
As Res_Str;

Output :

Res_Str
NULL
1 row in set (0.00 sec)

Example-4 :

Let's Consider a database table called Workerlogin with the following records:

WorkIDNameDateLoginTime
1John2019-10-2509:20:38
2Marry2019-10-2509:21:05
3Jo2019-10-2509:24:35
4Kim2019-10-2509:25:24
5Ramesh2019-10-2509:27:16

The following query can be used to get the 2nd element from the List of strings specified by column records:

SELECT *,
ELT(2, Name, Date, LoginTime) AS ELT_Value
FROM Workerlogin;

This will produce a result similar to the following:

EmpIDNameDateLoginTimeELT_Value
1John2019-10-2509:20:382019-10-25
2Marry2019-10-2509:21:052019-10-25
3Jo2019-10-2509:24:352019-10-25
4Kim2019-10-2509:25:242019-10-25
5Ramesh2019-10-2509:27:162019-10-25
6Suresh2019-10-2509:28:192019-10-25

Application of MySQL ELT() function:

This function is used to return the string, which is at the index number specified in the argument list.

Summary:

In the above context, we have learned how we can use the ELT() function in MySQL used to return the string, which is at the index number specified in the argument list.


Related Topics

MySQL Vs MongoDB

What is MongoDB? MongoDB is a distributed, open-source, cross-platform document-based database which was created to scale and develop applications simply. It was created as a NoSQL database by MongoDB Inc. MongoDB gets...

6 minutes read.

MySQL ISNULL function

This function is used to check the null value in table data. It returns the result in a Boolean form. If table data is null, then the output becomes 1....

2 minutes read.

MySQL variable

The MySQL variable is essential for storing data in the table. The variable declares data with a specific name or label to avoid confusion. This data label is used in...

6 minutes read.

MySQL COALESCE function

This statement displays the first non-null value of the table data. The COALESCE function returns a null value when all values of the table are null or do not find...

3 minutes read.

MySQL DATE_ADD() function

In this context, we will learn how we can use the MySQL DATE_ADD() function with proper syntax and good examples. Introduction of MySQL DATE_ADD() function In MySQL, the DATE_ADD() function is used...

3 minutes read.

MySQL Features

Features of MySQL MySQL is a relational database management system (RDBMS): It is a collection of many programs and makes relations with many other programs. Easy to use MySQL database: MySQL...

2 minutes read.

MySQL View

Introduction MySQL View is a virtual table to create a clone of the base table. The View does not contain its values or data. MySQL View creates to connect more than...

12 minutes read.

MySQL RIGHT() Function

In this context, we will learn how we can use the MySQL RIGHT() Function with proper syntax and good examples. Introduction of MySQL RIGHT() function The RIGHT() function in MySQL is used...

3 minutes read.

MySQL LIKE() function

In this context, we will learn how we can use the MySQL LIKE() function with proper syntax and good examples. Introduction of MySQL LIKE() function The LIKE function is a logical function...

4 minutes read.

MySQL MAX function

The MAX function is a type of aggregation function that determines the maximum value of the table data. This function works on numerical data type values. If the table displays...

4 minutes read.

MySQL MOD() function

In this context, we will learn how we can use the MySQL MOD() function with proper syntax and good examples. Introduction of MySQL MOD() function Basically, in MySQL, the MOD() function is...

3 minutes read.

MySQL RAND() function

In this context, we will learn how we can use the MySQL RAND() function with proper syntax and good examples. Introduction of MySQL RAND() function Basically, in MySQL the RAND() function is...

3 minutes read.

MySQL Union

MySQL contains the same categories of data in a different table. Sometimes, you require multiple tables to collect data together. MySQL union is a function to combine two table's data...

5 minutes read.

MySQL logical conditions

MySQL logical conditions Introduction MySQL handles data with clauses, operators, and conditions. The logical condition is used to compare information and returns the required output. This condition applies logic to MySQL expressions...

7 minutes read.

MySQL PERIOD_DIFF() function

In this context, we will learn how we can use the MySQL PERIOD_DIFF() function with proper syntax and good examples. Introduction of MySQL PERIOD_DIFF() function This function in MySQL is used to...

2 minutes read.

MySQL FIELD() function

In this context, we will learn how we can use the MySQL FIELD() function with proper syntax and good examples. Introduction of MySQL FIELD() function The index position of a mentioned value...

3 minutes read.

MySQL FLOOR() function

In this context, we will learn how we can use the MySQL FLOOR() function with proper syntaxes and examples. Introduction of MySQL Floor() function: FLOOR() function in MySQL is used to return...

3 minutes read.

MySQL ROUND() function

In this context, we will learn how we can use the MySQL ROUND() function with proper syntax and good examples. Introduction of MySQL ROUND() function The ROUND() function in MySQL is used...

3 minutes read.

MySQL PERIOD_ADD() function

In this context, we will learn how we can use the MySQL PERIOD_ADD() function with proper syntax and good examples. Introduction of MySQL PERIOD_ADD() function In MySQL, PERIOD_ADD() function will help to...

2 minutes read.

MySQL Error 1046 - No Database Selected

What is MySQL? MySQL is a Relational Database Management System (RDBMS). SQL in MySQL is the abbreviation of "Structured Query Language", which Oracle developed it in 1995. It is one of...

1 minute read.