Intellipaat 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?

2 Answers

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.

0 votes
ago by (1.5k points)

You can use the equality operator ‘=’ for checking whether two strings are equal or not in SQL.

Here’s how you can implement it-

SELECT *You can use the equality operator ‘=’ for checking whether two strings are equal or not in SQL.

Here’s how you can implement it-

SELECT *

FROM table_name

WHERE string_col1 = string_col2;

FROM table_name

WHERE string_col1 = string_col2;

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

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...