Home > Database > Mysql Tutorial > 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
Release: 2023-09-04 23:09:06
forward
1539 people have browsed it

如何使用 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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template