What would be the effect on MySQL output if we have the combination of NULL and other values in the list of strings, provided as arguments in FIELD() function?


There will be a significant change in the output if we have the combination of NULL and other values in the list of strings, provided as arguments in FIELD() function. Following example will demonstrate it

Example

mysql> Select FIELD('good','Ram','is','good','boy');
+---------------------------------------+
| FIELD('good','Ram','is','good','boy') |
+---------------------------------------+
|                                     3 |
+---------------------------------------+
1 row in set (0.00 sec)

As we can observe from the above output the index number of search string ‘good’ is 3. Now, if we will add NULL in the list of string then there will be a significant change in the output as follows −

mysql> Select FIELD('good','Ram','is',NULL,'good','boy');
+---------------------------------------------+
| FIELD('good','Ram','is',NULL,'good','boy')  |
+---------------------------------------------+
|                                           4 |
+---------------------------------------------+
1 row in set (0.00 sec)

It means that MySQL will compare the search string with NULL also.

Updated on: 30-Jul-2019

45 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements