Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (55.6k points)

Can anyone tell me how to compare two strings in SQL?

1 Answer

0 votes
by (119k points)

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.

Related questions

0 votes
1 answer
asked Apr 29, 2020 in SQL by Sudhir_1997 (55.6k points)
0 votes
1 answer
asked Apr 28, 2020 in SQL by Sudhir_1997 (55.6k points)
0 votes
1 answer
asked Apr 28, 2020 in SQL by Sudhir_1997 (55.6k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories

...