×

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 Join

The relational database system needs to interconnect multiple tables with each other. MySQL is a popular and easy data management system to connect multiple tables. The foreign key is used...

5 minutes read.

MySQL EXPORT_SET() function

In this context, we will learn how we can use the MySQL EXPORT_SET() function with proper syntax and good examples. Introduction of MySQL EXPORT_SET() function This function returns a string and shows...

3 minutes read.

MySQL GREATEST function

This statement displays the greatest values of the table. The GREATEST function returns a null value when the table contains a null value. The GREATEST function needs a minimum of...

2 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 MIN function

The MIN() function determines the minimum or lowest value of the data set. This function works on numerical data type values. If the table displays zero value, then the row...

4 minutes read.

MySQL Show index

This query helps to access and retrieve table information. This syntax displays the required index or all indexes of the table. It also displays the index type as per the...

3 minutes read.

MySQL LOCATE() function

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

3 minutes read.

MySQL QUARTER() function

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

3 minutes read.

MySQL DELETE JOIN

Sometimes join becomes complicated and unwanted. In such cases, we can delete the unwanted joins in the tables. You can delete inner join, left join, right join as per requirement....

3 minutes read.

MySQL TAN() Function

Basically, the TAN() function in MySQL is used to give back the tangent of a mentioned number.In any kind of right-angle triangle, the tangent of an angle is the length...

2 minutes read.

MySQL MONTHNAME() function

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

3 minutes read.

find_in_set() function in MySQL

This Function is used for finding the position of a particular string from the list of strings. For suppose if the specified string is repeated multiple times, then this functions...

4 minutes read.

MySQL DATEDIFF() function

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

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 LOAD_FILE() function

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

3 minutes read.

MySQL COUNT function

The count function returns the number of rows in the table. This function shows either the entire rows count or the required row count of the table. It determines the...

5 minutes read.

MySQL RIGHT JOIN

MySQL right join links two tables with each other. The left table column connects with the complete right side table. Each row of the right table tries to connect with...

4 minutes read.

MySQL Subquery

The subquery is a MySQL query used to manage data operations. Mainly subquery helps to retrieve data with the necessary condition. It creates a nested query with two different queries....

5 minutes read.

MySQL Aggregate function

The aggregation function works on the multiple values and returns single value output.  It makes the advanced and complex operation simple. The summation (SUM), MAX, AVG, MIN, COUNT functions are...

5 minutes read.

MySQL INSERT() Function

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

2 minutes read.