Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT)

Tags:

sql

mysql

Here is my query:

INSERT INTO location_province(name, country)   
SELECT child.name
      ,location_country.id
  FROM location_1 child
 INNER JOIN location_1 parent
    ON child.parent_id = parent.id
 INNER JOIN location_country
    ON location_country.name = parent.name
 WHERE child.location_type = 1

It throws this error:

#1267 - Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '='

What's wrong and how can I fix it?


Note: Adding COLLATE utf8_unicode_ci in the end of query doesn't work either.

like image 452
Martin AJ Avatar asked Aug 10 '17 18:08

Martin AJ


People also ask

What is the difference between utf8_general_ci and utf8_unicode_ci?

In short: utf8_unicode_ci uses the Unicode Collation Algorithm as defined in the Unicode standards, whereas utf8_general_ci is a more simple sort order which results in "less accurate" sorting results. If you don't care about correctness, then it's trivial to make any algorithm infinitely fast.

What is utf8_general_ci?

utf8_general_ci is a legacy collation that does not support expansions, contractions, or ignorable characters. It can make only one-to-one comparisons between characters.

What is utf8mb4_unicode_ci?

utf8mb4_unicode_ci , which uses the Unicode rules for sorting and comparison, employs a fairly complex algorithm for correct sorting in a wide range of languages and when using a wide range of special characters.


1 Answers

Yeah, that's because of the JOIN ON clauses and per error, collation of those columns involved in ON condition doesn't matches. Collation of those column must match. I mean the below lines

ON child.parent_id = parent.id  ------ 1
 INNER JOIN location_country
    ON location_country.name = parent.name ------ 2

Check the tables on which you are joining and verify the same

Well, change the collation while joining like

 INNER JOIN location_country
    ON location_country.name collate utf8_general_ci = parent.name collate utf8_general_ci 
like image 126
Rahul Avatar answered Sep 23 '22 12:09

Rahul