If we want to compare the data values of two columns, then we need to provide the name of the column as a parameter to the MySQL STRCMP() function. Suppose we have a table called "Marks" which contains the names of students and their safe marks in different subjects. Now, if we want to know whether a certain student got more, less or equal marks in two subjects, we can illustrate using STRCMP() function as shown below -
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 above query will compare the math and hindi scores of a student named "Rahul". It is clear from the result set that Rahul got higher marks in Mathematics than in Hindi.
The above is the detailed content of How to compare column data values of a table using the MySQL STRCMP() function?. For more information, please follow other related articles on the PHP Chinese website!