©SQL :: Manager
HomeProgram InformationTechnical detailsFree downloadDonate for a cup of coffee
myway SQL Manager for MySQL and MariaDB, Download on Uptodown
SQL functionMySQLMariaDB

The STRCMP SQL Function in MySQL and MariaDB - Compare strings

STRCMPSyntax:STRCMP(String 1, String 2)
Return value:INTEGER
Function type:Comparison function
Function Description

The STRCMP() function compares two strings.

If the strings are equal, the function returns 0.

If "String 1" is greater than "String 2", the function returns 1.

If "String 1" is less than "String 2", the function returns -1.

Numerical values ​​are interpreted as character strings.

If one or both of the arguments are NULL, STRCMP() returns NULL.

SQL Examples for the STRCMP function

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19

SELECT strcmp('abc''abc');
SELECT strcmp('abc''bcd');
SELECT strcmp('abc''abc2');
SELECT strcmp('abc2''abc');

SELECT strcmp(1, 1);
SELECT strcmp(1, 2);
SELECT strcmp(2, 1);
SELECT strcmp(22, 3);
SELECT strcmp(22, 2);
SELECT strcmp(22, 22.0);
SELECT strcmp(falsetrue);
SELECT strcmp(truefalse);

SELECT strcmp(null'abc');
SELECT strcmp('abc'null);
SELECT strcmp(nullnull);

strcmp('abc', 'abc')
bigint(2)
0
strcmp('abc', 'bcd')
bigint(2)
-1
strcmp('abc', 'abc2')
bigint(2)
-1
strcmp('abc2', 'abc')
bigint(2)
1
strcmp(1, 1)
bigint(2)
0
strcmp(1, 2)
bigint(2)
-1
strcmp(2, 1)
bigint(2)
1
strcmp(22, 3)
bigint(2)
-1
strcmp(22, 2)
bigint(2)
1
strcmp(22, 22.0)
bigint(2)
-1
strcmp(false, true)
bigint(2)
-1
strcmp(true, false)
bigint(2)
1
strcmp(null, 'abc')
bigint(2)
NULL
strcmp('abc', null)
bigint(2)
NULL
strcmp(null, null)
bigint(2)
NULL
The examples were created with the MyWAY SQL manager: Download

How to use the STRCMP() function in MySQL and MariaDB databases

In MySQL and MariaDB the STRCMP() function can be used to compare two strings and get an integer value representing the result of the comparison, which can be used to perform case-sensitive string comparisons, such as for conditional statements or sorting operations of SQL queries in databases.
STDDEV_POPSTDDEV_SAMPSTR_TO_DATESTRCMPSUBDATESUBSTRSUBSTRING

Further MySQL und MariaDB SQL Comparison functions

COALESCECOALESCE(%, %)
More about COALESCE Function

DECODE_ORACLEDECODE_ORACLE()
More about DECODE_ORACLE Function

GREATESTGREATEST(%, %)
More about GREATEST Function

INTERVALINTERVAL(%, %)
More about INTERVAL Function

IFIF(Expression, Value1, Value2)
More about IF Function

LEASTLEAST(%, %)
More about LEAST Function

Numeric functionsString functionsRegular ExpressionsDate and Time functions
Comparison functionsEncryption & CompressionConversion functionsNULL functions
Aggregate functionsWindow functionsJSON functionsGeometric functions
Sequence functionsInformation functionsDynamic ColumnsMiscellaneous functions
More information about the STRCMP SQL function: mysql.com and mariadb.com and w3schools.com
Updated: 2023-09-24ImprintContactTerms & conditionsPrivacy & CookiesUpdatesSitemapFacebookLinkedinTwitterStatistics©2020-2024 Heino Cunze-Fischer