
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check Similarity Between Two Strings in MySQL
Similarity between two strings can be checked with the help of ‘strcmp()’ function. Here are the conditions.
If both strings are equal, then it returns 0.
If first string is less than the second string, it returns -1.
If first string is greater than the second string, it returns 1.
Here is an example.
Case 1 − If both strings are equal.
The following is the query.
mysql > SELECT STRCMP("demo", "demo");
The following is the output of the above query.
+------------------------+ | STRCMP("demo", "demo") | +------------------------+ | 0 | +------------------------+ 1 row in set (0.00 sec)
Case 2 − If first string is less than the second string.
The following is the query.
mysql> SELECT STRCMP("demo", "demo1234");
The following is the output of the above query.
+----------------------------+ | STRCMP("demo", "demo1234") | +----------------------------+ | -1 | +----------------------------+ 1 row in set (0.00 sec)
Case 3 − If first string is greater than the second string.
The following is the query.
mysql> SELECT STRCMP("demo1", "demo");
The following is the output.
+-------------------------+ | STRCMP("demo1", "demo") | +-------------------------+ | 1 | +-------------------------+ 1 row in set (0.00 sec)
Advertisements