兩張表分別爲:html
CREATE TABLE `tb_user` ( `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '用戶編號(自增字段)', `userName` varchar(32) NOT NULL DEFAULT '' COMMENT '用戶暱稱', # ... PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1DEFAULT CHARSET=utf8 COMMENT='用戶表'; CREATE TABLE `tb_sms_message` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `tel` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '手機號', # ... PRIMARY KEY (`id`), ) ENGINE=InnoDB AUTO_INCREMENT=1DEFAULT CHARSET=utf8;
報錯信息以下:sql
Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '='spa
SELECT * FROM `tb_sms_message` where tel not IN (select userName from tb_user);
兩個關聯的字段的collate不一致,沒法直接關聯。code
這裏咱們能夠對字段的校對集轉化爲一致:htm
CONVERT(tel USING utf8) COLLATE utf8_general_ciblog
修改後的SQL:ci
SELECT * FROM `tb_sms_message` where CONVERT(tel USING utf8) COLLATE utf8_general_ci not IN (select userName from tb_user);
網上搜了挺多的,可是真正提到我這個問題的解決方式:unicode
http://www.cnblogs.com/mrma/p/3440992.htmlio