In SQL, we can compare two strings using STRCMP () function. STRCMP () returns ‘0’ when the two strings are the same, returns ‘-1’ if the first string is smaller than the second string, and returns 1 if the first string is larger than the second string.
Here is the syntax to use STRCMP () function:
STRCMP (string1, string2)
The following SQL query returns ‘0’ since both strings are same.
SELECT STRCMP (‘SQL tutorial’, ‘SQL tutorial’);
The following SQL query returns ‘-1’ since the first string is smaller than the second.
SELECT STRCMP (‘SQL tutorial’, ‘SQL tutorial blog’);
If you want to take a course that can provide Instructor-led training and certification, I recommend this SQL Training by Intellipaat.
You can master these SQL statements, queries and become proficient in SQL queries by enrolling in an industry-recognized SQL course.