0
votes

i am receiving the following error message

[Err] 1267 - Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='

Subquery contains Union of two tables from two different databases. The query i am trying to execute is given below

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`;
1

1 Answers

0
votes

It happened due to variation in collation.If you give any values explicitly in Query,collation be will taken from Connection.

You can use something like this.

     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`;`

OR

  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`;