MySQL STRCMP() function
STRCMP() function
MySQL strcmp() function is used to compare two strings. It returns 0 if both of the strings are same and returns -1 when the first argument is smaller than the second according to the defined order and 1 when the second one is smaller the first one.
Syntax:
STRCMP (expr1, expr2)
Argument:
Name | Description |
---|---|
expr1 | First string for comparison. |
expr2 | Second string for comparison. |
Syntax Diagram:

MySQL Version: 5.6
Video Presentation:
Example : MySQL STRCMP() function
In the MySQL statement stated below, using the STRCMP() function, two strings are compared, and since it is found that the strings are same, it returns 0.
Code:
SELECT STRCMP('mytesttext', 'mytesttext');
Sample Output:
mysql> SELECT STRCMP('mytesttext', 'mytesttext'); +------------------------------------+ | STRCMP('mytesttext', 'mytesttext') | +------------------------------------+ | 0 | +------------------------------------+ 1 row in set (0.01 sec)
MySQL STRCMP() function with unmatched strings
The MySQL statement stated below, using the STRCMP() function to compare two strings and returns -1 according to the default comparison behavior
Code:
SELECT STRCMP('mytesttext', 'mytest_text');
Sample Output:
mysql> SELECT STRCMP('mytesttext', 'mytest_text'); +-------------------------------------+ | STRCMP('mytesttext', 'mytest_text') | +-------------------------------------+ | -1 | +-------------------------------------+ 1 row in set (0.00 sec)
All String Functions
- Weekly Trends
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
- JavaScript functions Exercises
- Python Tutorial
- Python Array Exercises
- SQL Cross Join
- C# Sharp Array Exercises