SelectName,STRCMP(Math,Hindi) fromstudentmarksWHEREName='Rahul';+-------+--"/> SelectName,STRCMP(Math,Hindi) fromstudentmarksWHEREName='Rahul';+-------+--">

Home  >  Article  >  Database  >  How to compare column data values ​​of a table using the MySQL STRCMP() function?

How to compare column data values ​​of a table using the MySQL STRCMP() function?

WBOY
WBOYforward
2023-09-04 23:09:061497browse

如何使用 MySQL STRCMP() 函数比较表的列数据值?

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 -

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 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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete