Jump to: navigation, search

Mysql STRCMP

From w3cyberlearnings

Contents

MySQL STRCMP Function

This function compares two string.

Syntax STRCMP

  • Str1: Input 1
  • Str2: Input 2
STRCMP(Str1, Str2);

Return

  • Return 0, if both string is equal (ie. str1=str2)
  • Return 1, if str1 is larger than str2 (ie. str1 > str2)
  • Return -1, if str1 is smaller than str2 (ie. str1 < str2)

Example 1

mysql> SELECT STRCMP('good','good');
+-----------------------+
| STRCMP('good','good') |
+-----------------------+
|                     0 |
+-----------------------+
1 row in set (0.00 sec)

Example 2

mysql> SELECT STRCMP('good','good2');
+------------------------+
| STRCMP('good','good2') |
+------------------------+
|                     -1 |
+------------------------+
1 row in set (0.00 sec)

Example 3

mysql> SELECT STRCMP('good2','good');
+------------------------+
| STRCMP('good2','good') |
+------------------------+
|                      1 |
+------------------------+
1 row in set (0.00 sec)

Related Links


Navigation
Web
SQL
MISC
References