myslq数据库用union all查询出现 #1271 - Illegal mix of collations for operation 'UNION'

出现 #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;

posted @ 2018-03-13 17:30  小黑s  阅读(1193)  评论(0编辑  收藏  举报