![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How MySQL FIELD() and ELT() functions are complements of each other?
On the basis of the working of both the functions, we can say that both are the complement of each other. Actually, as we know that FIELD() function, on providing a string as an argument, returns the index number of the string from string list and ELT() function, on providing index number as an argument, returns the string from string list. In the following example, we have applied both the functions on the same string, it would demonstrate the concept −
Example
mysql> SELECT ELT(4, 'Ram','is','good','boy')As Result; +--------+ | Result | +--------+ | boy | +--------+ 1 row in set (0.00 sec) mysql> SELECT FIELD('boy', 'Ram','is','good','boy')As Result; +--------+ | Result | +--------+ | 4 | +--------+ 1 row in set (0.00 sec)
As we can see from the above result set that one is getting index number as an argument to give the string as output and another is taking a string as an argument to give the index number as output. Hence, they both are the complement of each other.
Advertisements