myslq数据库用union all查询出现 #1271

出现 #1271 - Illegal mix of collations for operation 'UNION' 的原因是两个字符编码不匹配造成的。

我遇到的是  utf8_general_ci 和 utf8_unicode_ci 这两个编码不匹配,

只要在查询语句的对应列前加  COLLATE utf8_unicode_ci 就可以将  utf8_general_ci 的字符编码转为 utf8_unicode_ci 。

select name COLLATE utf8_unicode_ci as userName  from table1

union all

select name as userName   from table;

原文地址:https://www.cnblogs.com/xiaoheis/p/8559400.html