MySQL: STRCMP Function

  • Post author:
  • Post category:MySQL
  • Post comments:1 Comment
MySQL STRCMP Function

In this guide, we will explain how to use the MySQL STRCMP function with syntax and examples.

Description

The MySQL STRCMP function tests whether two strings are the same using the current character set.

Syntax

The syntax for the STRCMP function in MySQL is:

STRCMP( string1, string2 )

Parameters or Arguments

string1 and string2

The two strings to be compared to each other.

Note

  • If string1 and string2 are the same, the STRCMP function will return 0.
  • If string1 is smaller than string2, the STRCMP function will return -1.
  • If string1 is larger than string2, the STRCMP function will return 1.

Applies To

The STRCMP function can be used in the following versions :

  • MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23

Example

Let’s look at some STRCMP function examples and explore how to use the STRCMP function.

For example:

mysql> SELECT STRCMP('adglob.in', 'adglob.in');
Result: 0

mysql> SELECT STRCMP('baldev.com', 'adglob.in');
Result: -1

mysql> SELECT STRCMP('adglob.in', 'baldev.com');
Result: 1

Next Topic : Click Here

This Post Has One Comment

Leave a Reply