×

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

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

2 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 Character Length Function

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

2 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 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 Tutorial

In this tutorial, you will get information about the MySQL management system. This tutorial will cover the basic and advanced level MySQL concepts with examples that will help you become...

5 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 Create index

An index creation helps to make a row of the table unique. The index operates and handles table data quickly. MySQL index requires NOT NULL column constraint. The index column...

2 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 Table Query

MySQL table query A database stored a lot of data and divided them into different relations known as tables. Each database can contain more than one table. These tables are created...

7 minutes read.

MySQL POWER() function

In this context, we will learn how we can use the MySQL POWER() function with proper syntax and good examples. Introduction of MySQL POWER() function The value of a number raised to...

3 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 INSTR() Function

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

4 minutes read.

MySQL RPAD() function

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

2 minutes read.

MySQL Table

Introduction MySQL table is an essential part of the system. MySQL table stores data using index, rows, and columns. It accesses data from the server quickly because of the table—this table...

22 minutes read.

MySQL Full text index

Full text index The full-text index in the table isused to search the full text of the data. This index assigns to the table using a "FULLTEXT" keyword. First, the table...

3 minutes read.

MySQL Truncate() Function

In this context, we will learn how we can use the MYSQL TRUNCATE function to truncate a number to a mentioned number of decimal places. Syntax of MySQL Truncate Function A number...

2 minutes read.

MySQL Descending Index

Descending Index It is a type of index that stores key values in descending order. This query improves the performance of an index query. MySQL system displays the index as per...

3 minutes read.

MySQL FORMAT() function

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

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.