Compare Strings in MySQL

In SQL, a built-in function is a programming object that takes zero or more inputs and returns a value. A feature that is built into an application and can be used by end users. Built-in functions in SQL SELECT expressions help in calculating numbers, casting or converting data, changing the format of fields, and analyzing data.

Data analysis, data transformation, data conversion, data manipulation, arithmetic operations, and output formatting are all made easier by the numerous built-in functions that MySQL provides. In this article, we’ll discuss the STRCMP function, which facilitates comparing the two provided strings.

Note that this function gives a result of 0 if string1 is equal to string2.
And returns -1 if string1 is less than string2.
And gives 1 if string1 is greater than string2 and also if both the strings are not equal.

Returns: 0

SELECT STRCMP(“201”, “203”);
Returns: -1

SELECT STRCMP(“small data and sql”, “bigdata and sql”);
Returns: 1

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s