Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

sql
mysql
string
communitycreator

What is STRCMP() in SQL?

Harris Amjad

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The STRCMP() function compares two strings sent as a parameter.

Figure 1 shows a visual representation of the STRCMP() function.

Figure 1: Visual representation of STRCMP() function

Syntax

STRCMP(str1, str2)

Parameter

The STRCMP() function takes two strings as a parameter.

Return value

The STRCMP() function compares two strings sent as a parameter.

  • If both the strings are equal, then this function returns 0.
  • If string-1 > string-2, then this function returns 1.
  • If string-1 < string-2, then this function returns -1.
  • If any of the strings is NULL, then this function returns NULL.

Code

-- Both the strings are same
SELECT STRCMP('educative','educative');
-- string-1 < string-2
SELECT STRCMP('edpresso','educative');
-- string-1 > string-2
SELECT STRCMP('educative','edpresso');
-- string-1 = NULL
SELECT STRCMP(NULL,'edpresso');

RELATED TAGS

sql
mysql
string
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring