MySQL STRCMP function is one of the String Functions, which compares two strings and returns an integer 0, 1, -1. Let us see how to write this method query to compare two strings with an example. The basic syntax of STRCMP of a string is as shown below:

STRCMP(String_Expression1, expression2)

If exp1 = expr2 then 0. if exp1 is greater than expr2, then 1 is returned; otherwise, -1 is returned.

MySQL STRCMP Function Example

The STRCMP function compares the two given string expressions. The following query shows multiple ways to use this STRCMP Function.

SELECT STRCMP('mysql', 'mysql');

SELECT STRCMP('mysql', 'mysqla');

SELECT STRCMP('mysqla', 'mysql');
Example 1

It is another example of this MySQL compare function.

SELECT STRCMP('mysql', 'MySQL');

SELECT STRCMP('mysql.', 'mysql..');

STRCMP Example 2