## 10.8.2 COLLATE Clause Precedence 

•With WHERE : 

•With HAVING : 

SELECT k FROM t1 GROUP BY k HAVING k = _latin1 ’Müller’ COLLATE latin1_german2_ci; 

SELECT * FROM t1 WHERE _latin1 ’Müller’ COLLATE latin1_german2_ci = k; 

SELECT * FROM t1 WHERE k LIKE _latin1 ’Müller’ COLLATE latin1_german2_ci; 

The COLLATE  clause has high precedence (higher than || ), so the following two expressions are equivalent: 

## 10.8.3 Character Set and Collation Compatibility 

x || y COLLATE z x || (y COLLATE z) 

Each character set has one or more collations, but each collation is associated with one and only one character set. Therefore, the following statement causes an error message because the latin2_bin collation is not legal with the latin1  character set: 

## 10.8.4 Collation Coercibility in Expressions 

mysql> SELECT _latin1 ’x’ COLLATE latin2_bin; ERROR 1253 (42000): COLLATION ’latin2_bin’ is not valid for CHARACTER SET ’latin1’ 

In the great majority of statements, it is obvious what collation MySQL uses to resolve a comparison operation. For example, in the following cases, it should be clear that the collation is the collation of column x : 

SELECT x FROM T ORDER BY x; SELECT x FROM T WHERE x = x; SELECT DISTINCT x FROM T; 

However, with multiple operands, there can be ambiguity. For example, this statement performs a comparison between the column x  and the string literal ’Y’ : 

SELECT x FROM T WHERE x = ’Y’; 

If x  and ’Y’  have the same collation, there is no ambiguity about the collation to use for the comparison. But if they have different collations, should the comparison use the collation of x , or of ’Y’ ? Both x  and ’Y’  have collations, so which collation takes precedence? 

A mix of collations may also occur in contexts other than comparison. For example, a multiple-argument concatenation operation such as CONCAT(x,’Y’)  combines its arguments to produce a single string. What collation should the result have? 

To resolve questions like these, MySQL checks whether the collation of one item can be coerced to the collation of the other. MySQL assigns coercibility values as follows: 

