
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
Compare Column Data Values Using MySQL STRCMP Function
If we want to compare the data values of two columns then we need to provide the name of the columns as arguments of MySQL STRCMP() function. Suppose we have a table named ‘Marks’ which contains the name of the student and their secured marks in different subjects. Now, if we want to know that a particular student has got more or less or equal marks in two subjects then it can be illustrated using STRCMP() function as follows −
Example
mysql> Select Name, STRCMP(Math,Hindi) from student marks WHERE Name = 'Rahul'; +-------+--------------------+ | Name | STRCMP(Math,Hindi) | +-------+--------------------+ | Rahul | 1 | +-------+--------------------+ 1 row in set (0.00 sec)
The query above will compare the marks of Math and Hindi for a student named ‘Rahul’. It is clear from the result set that Rahul secure more marks in Math rather than in Hindi.
Advertisements