This article will introduce to you how to use the "<=>" operator in MySQL. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.
" operator in MySQL" >
Question:
I was looking at a previous developer’s code and saw
?1WHERE p.name <=>NULL
What does the <=> symbol mean in this query statement? Is it the same as the = sign? Or is it a grammatical error? But no errors or exceptions are shown. I already know the symbols such as <> = != in mysql.
Best answer:
The same points as the = sign
Like the regular = operator, two values are compared, and the result is 0 (not equal) or 1 (equal); in other words: 'A'<=>'B' gets 0 and 'a'<=>'a' gets 1.
2. The difference between
and = operator is that the value of NULL has no meaning. Therefore, the = operator cannot treat NULL as a valid result. So: please use <=>,
'a' <=> NULL gets 0 NULL<=> NULL gets 1. Contrary to the = operator, the rule for the = operator is 'a'=NULL, and the result is NULL. Even NULL = NULL, the result is NULL. By the way, almost all operators and functions on MySQL work this way, because comparison with NULL is basically meaningless.
Use
When two operands may contain NULL, you need a consistent statement.
?1...WHERE col_a <=> ? ...
The placeholder here may be a constant or NULL. When using the <=> operation , you do not need to make any changes to the query statement.
Related operators
In addition to <=>, there are two other operators used to compare a certain value with NULL, which is IS NULL and IS NOT NULL. They are part of the ANSI standard and therefore can be used in other databases. And <=> can only be used in mysql.
You can think of <=> as a dialect in mysql.
?12'a' IS NULL ==>'a' <=>NULL'a' IS NOT NULL ==>NOT('a' <=>NULL)
According to this, you can change this query statement segment to be more portable:
?1WHERE p.name IS NULL
Related recommendations: "mysql tutorial 》
The above is the detailed content of How to use the "<=>" operator in MySQL. For more information, please follow other related articles on the PHP Chinese website!