Mysql error: Illegal mix of collations for operation 'UNION'

引发异常的原因

两个 UNION 的字段的字符编码不一致,例如:utf8_general_ci 与 utf8_unicode_ci

解决方法

  1. 将字符编码设置为一致
  2. SELECT 语句中使用 COLLATE utf8_general_ci
    e.g
SELECT 
   comment COLLATE utf8_general_ci
FROM comments
UNION
SELECT 
   comment
FROM videos

参考

Mysql error: Illegal mix of collations for operation 'UNION'

你可能感兴趣的:(Mysql error: Illegal mix of collations for operation 'UNION')