content_image/707130.jpg content_image/707131.jpg
describes the rules for comparison operations performed by these and similar functions for determining their return values. 

<img src='content_image/707130.jpg'>

<img src='content_image/707131.jpg'>

## Note 

In previous versions of MySQL, when evaluating an expression containing LEAST()  or GREATEST() , the server attempted to guess the context in which the function was used, and to coerce the function’s arguments to the data type of the expression as a whole. For example, the arguments to LEAST("11", "45", "2")  are evaluated and sorted as strings, so that this expression returns "11" . In MySQL 8.0.3 and earlier, when evaluating the expression LEAST("11", "45", "2") + 0 , the server converted the arguments to integers (anticipating the addition of integer 0 to the result) before sorting them, thus returning 2. 

Beginning with MySQL 8.0.4, the server no longer attempts to infer context in this fashion. Instead, the function is executed using the arguments as provided, performing data type conversions to one or more of the arguments if and only if they are not all of the same type. Any type coercion mandated by an expression that makes use of the return value is now performed following function execution. This means that, in MySQl 8.0.4 and later, LEAST("11", "45", "2") + 0  evaluates to "11" + 0  and thus to integer 11. (Bug #83895, Bug #25123839) 

To convert a value to a specific type for comparison purposes, you can use the CAST()  function. String values can be converted to a different character set using CONVERT() . See Section 12.11, “Cast Functions and Operators” . 

By default, string comparisons are not case-sensitive and use the current character set. The default is utf8mb4 . 

• = 

Equal: 

mysql> SELECT 1 = 0; -> 0 mysql> SELECT ’0’ = 0; -> 1 mysql> SELECT ’0.0’ = 0; -> 1 mysql> SELECT ’0.01’ = 0; -> 0 mysql> SELECT ’.01’ = 0.01; -> 1 

For row comparisons, (a, b) = (x, y)  is equivalent to: 

(a = x) AND (b = y) 

• <=> 

NULL -safe equal. This operator performs an equality comparison like the =  operator, but returns 1  rather than NULL  if both operands are NULL , and 0  rather than NULL  if one operand is NULL . 

The <=>  operator is equivalent to the standard SQL IS NOT DISTINCT FROM  operator. 

mysql> SELECT 1 <=> 1, NULL <=> NULL, 1 <=> NULL; -> 1, 1, 0 mysql> SELECT 1 = 1, NULL = NULL, 1 = NULL; -> 1, NULL, NULL 

