0

我收到以下错误消息

[Err] 1267 - 非法混合排序规则 (latin1_swedish_ci,IMPLICIT) 和 (utf8_general_ci,COERCIBLE) 用于操作 '='

子查询包含来自两个不同数据库的两个表的联合。我试图执行的查询如下

SELECT  c.CORRECTION_NO FROM    (
    SELECT  "regm2017" as `SESSION`,SERIALNO,NAME,FATHER
    FROM    regm2017.master r17
    WHERE   r17.IS_DELETED=0
    UNION
    SELECT  "regm2016" as `SESSION`,SERIALNO,NAME,FATHER
    FROM    regm2016.master r16
    WHERE   r16.IS_DELETED=0
    ) as r JOIN    corrections_registration as c ON      c.SERIALNO = r.SERIALNO
    AND c.`SESSION`= r.`SESSION`;
4

1 回答 1

0

这是由于排序规则的变化而发生的。如果您在查询中明确给出任何值,排序规则将从连接中获取。

你可以使用这样的东西。

     SELECT c.CORRECTION_NO FROM (
     SELECT "regm2017" COLLATE utf8_general_ci as > `SESSION`,SERIALNO,NAME,FATHER
     FROM regm2017.master r17
     WHERE   r17.IS_DELETED=0
     UNION
     SELECT  "regm2016" COLLATE utf8_general_ci  as `SESSION`,SERIALNO,NAME,FATHER
     FROM    regm2016.master r16
     WHERE   r16.IS_DELETED=0
     ) as r JOIN    corrections_registration as c ON c.SERIALNO = 
     r.SERIALNO 
     AND c.`SESSION`= r.`SESSION`;`

或者

  SELECT c.CORRECTION_NO FROM    (
  SELECT  "regm2017" COLLATE latin1_swedish_ci as `SESSION`,SERIALNO,NAME,FATHER
  FROM    regm2017.master r17
  WHERE   r17.IS_DELETED=0
  UNION
  SELECT  "regm2016" COLLATE latin1_swedish_ci as `SESSION`,SERIALNO,NAME,FATHER
  FROM    regm2016.master r16
  WHERE   r16.IS_DELETED=0
  ) as r JOIN    corrections_registration as c ON      c.SERIALNO = r.SERIALNO
  AND c.`SESSION`= r.`SESSION`;
于 2017-05-19T05:34:41.837 回答