- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to 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)
- Related Articles
- How to compute the Cosine Similarity between two tensors in PyTorch?
- How to check if two strings are equal in Java?
- How to check whether now() falls between two specific dates in MySQL?
- Check if edit distance between two strings is one in Python
- How to add two or more strings in MySQL?
- Java Program to check for equality between two strings ignoring the case
- How to compare two strings which are numbers in MySQL?
- Which function in MySQL is used to add white spaces between two strings?
- Comparing two strings in MySQL?
- How to extract the strings between two words in R?
- How can we measure the similarity or distance between two vertices in a graph?
- What is the similarity between prepared statements and MySQL user variables?
- Java Program to Check if two strings are anagram
- Golang Program to Check if two Strings are Anagram
- How to extract a string that lies between two strings in R?

Advertisements