MySQL STRCMP() function
MySQL STRCMP() function is used to compare 2 strings.
The syntax:
STRCMP(exp1, exp2)
Explain: exp1 will be first string, and exp2 will be second string.
Note: No priority among exp1 and exp2, as it can compare both.
Example 1:
SELECT STRCMP('text', 'text2');
Output: -1
Explain: The result returns -1 if the first argument is smaller than the second argument
Example 2:
SELECT STRCMP('text2', 'text');
Output: 1
Explain: The result returns 1 if the second argument is greater than the first argument
Example 3:
SELECT STRCMP('text', 'text');
Output: 0
Explain: The result returns 0 if the first and second argument are the same
Note: STRCMP() uses the current character set when performing comparisons. This makes the default comparison behavior case insensitive unless one or both of the operands are binary strings.
- Forums:
