Home > Database > Mysql Tutorial > body text

What does '=' in mysql mean?

青灯夜游
Release: 2022-01-10 10:32:46
Original
3126 people have browsed it

In mysql, "=" means equality. It is a comparison operator. It is mainly used to compare whether the operands on both sides are equal. If they are equal, it returns 1. If they are not equal, it returns 0. Note that "=" cannot be used to judge the null value NULL, so if one or two operands are NULL, the result of the comparison operation is NULL.

What does '=' in mysql mean?

The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.

In mysql, "=" means equality and is a comparison operator.

= The operator is used to compare whether the operands on both sides are equal. If they are equal, it returns 1; if they are not equal, it returns 0. The specific syntax rules are as follows:

  • If one or two operands are NULL, the result of the comparison operation is NULL. (Reason: NULL cannot be used for = comparison.)

  • If both operands are strings, compare them as strings.

  • If both operands are integers, the comparison is based on integers.

  • If one operand is a string and the other operand is a number, MySQL can automatically convert the string to a number.

Example: Use = for equality judgment

mysql> SELECT 1=0,'2'=2,2=2,'0.02'=0,'b'='b',(1+3)=(2+2),NULL=null;
+-----+-------+-----+----------+---------+-------------+-----------+
| 1=0 | '2'=2 | 2=2 | '0.02'=0 | 'b'='b' | (1+3)=(2+2) | NULL=null |
+-----+-------+-----+----------+---------+-------------+-----------+
|   0 |     1 |   1 |        0 |       1 |           1 |      NULL |
+-----+-------+-----+----------+---------+-------------+-----------+
1 row in set (0.01 sec)
Copy after login

Analysis of running results:

  • ##2=2 The return values ​​of and '2' =2 are the same, both are 1, because MySQL automatically converts the character '2' into the number 2 when making the judgment.

  • 'b'='b' is the same character comparison, so the return value is 1.

  • The results of expression

    1 3 and expression 2 2 are both 4, so the results are equal, return The value is 1;

  • Since

    = cannot be used to judge the null value NULL, therefore NULL=null The return value is NULL.

[Related recommendations:

mysql video tutorial]

The above is the detailed content of What does '=' in mysql mean?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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 [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!