MySQL STRCMP Function

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 MySQL String STRCMP Function query to compare two strings with an example. The basic syntax of STRCMP of a string in MySQL 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 Example

The MySQL string compare function compares the two given string expression. The following query shows multiple ways to use this STRCMP String Function.

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

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

SELECT STRCMP('mysqla', 'mysql');
MySQL STRCMP Function 1

It is another example of this MySQL String compare function.

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

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

SELECT STRCMP('mysql', NULL);
MySQL STRCMP Function 2