报错:illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation '='

sql语句:

select t1.block_info, t2.zone 
from device_indoor_tbl t1 
left join blackwhitezone_tbl t2 on t1.block_info=t2.zone 

字符集编码不同:

报错信息:illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation '='

原因:字符集编码不同。

ps:按理说同一个数据库的字符集编码应该是一样的,奈何之前不知道什么原因数据库竟然有不同的编码,接手的时候数据库又不敢乱改,只能从sql语句着手想办法,百度了好久,最后还是问另外一个同事才解决的。

解决方法:将两个字段的字符集编码改成相同的。(建议修改成多数表所用的字符集编码,我的数据库多数表是utf8_general_ci编码,只有少数几张例外是utf8_unicode_ci)

修改后的sql语句:

select t1.block_info, t2.zone 
from device_indoor_tbl t1 
left join blackwhitezone_tbl t2 on t1.block_info=t2.zone COLLATE utf8_general_ci

 

posted @ 2017-10-20 15:16  皮卡丘的小智M  阅读(8537)  评论(0编辑  收藏  举报