str1 and str2 are two input strings to be compared.
Output is here
-1
if str1 is smaller than str2
0
if str1 is equal to str2
+1
if str1 is greater than str2
STRCMP() follows the collation of its string arguments. With a typical case-insensitive collation, values such as 'APPLE' and 'apple' compare as equal. Use a binary string or a case-sensitive collation when case must matter.
SELECTSTRCMP('APPLE', 'apple'); -- Output: 0
For an explicitly case-sensitive comparison, use a binary expression or a case-sensitive collation.
You can see in above display , STRCMP returns 0 ( both matching ) for comparison between strings Alex and alex. To make the comparison case sensitive we can use BINARY comparison. Using a binary expression makes the comparison byte-sensitive, so uppercase and lowercase bytes compare differently.
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery,
and web development at plus2net. The tutorials focus on clear explanations, working
examples, and code that readers can test and adapt while learning.