Judging from the working principles of these two functions, we can say that the two complement each other. In fact, we know that the FIELD() function returns the index number of the string from the string list when providing a string as a parameter, while the ELT() function returns the character from the string list when providing the index number as a parameter. string. In the example below, we have applied both functions on the same string, which will demonstrate the concept -
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 can be seen from the above result set, a Take an index number as an argument and a string as output, and the other one takes a string as argument and an index number as output. Therefore, they are complementary to each other.
The above is the detailed content of How do the MySQL FIELD() and ELT() functions complement each other?. For more information, please follow other related articles on the PHP Chinese website!