字符串与不同 COLLATION 的比较
String comparison with different COLLATION
MYSQL 数据库
数据库 1 - table - table1
id - int
标题 - utf8_general_ci
值 -
1, Bienvenue Chez les Châtis
2、农行
3、XYZ
数据库 2 - table - table2
id - 整数
标题 - utf8_unicode_ci
值 -
1, Bienvenue Chez les Ch'tis
2、农行
3、QWE
我在 table 中都有标题列表,因为 above.I 想要列出不相同的标题。
我尝试了很多不同的东西,但没有运气。
如何比较这些标题?
SELECT database1.table1.title as title1,database2.table2.title as title2
FROM database1.table1 JOIN database2.table2 ON (database1.table1.id =database2.table2)
WHERE database1.table1.title NOT LIKE database2.table2.title COLLATE utf8_general_ci
上述查询的结果:
Bienvenue Chez les Ch'tis, Bienvenue Chez les Ch'tis
XYZ, QWE
但我只想要下面的结果
XYZ、QWE
我想排除法文的,我想将其视为相同的标题。
’
是 ’
的 Mojibake。当以两种不同的方式存储 same 右单引号时,问题就来了。不是 COLLATION
问题。
首先,检查两个表以查看存储的内容:
SELECT HEX(title) FROM database1.table1 WHERE id = 1
您会发现的两种可能情况是:
C h ... t i s
43 68 E28099 74 69 73 -- correctly encoded with UTF-8
43 68 C3A2 E282AC E284A2 74 69 73 -- "double encoded"
(为清楚起见,我在 HEX 中添加了空格。)
如果其中一个表是 "doubly encoded",那么它在 INSERTing
期间被弄乱了。字符串将不比较相等。
discusses things further. Then see this 用于修复双重编码的文本。但请务必仅将其应用于损坏的数据。
MYSQL 数据库
数据库 1 - table - table1
id - int
标题 - utf8_general_ci
值 -
1, Bienvenue Chez les Châtis
2、农行
3、XYZ
数据库 2 - table - table2
id - 整数
标题 - utf8_unicode_ci
值 -
1, Bienvenue Chez les Ch'tis
2、农行
3、QWE
我在 table 中都有标题列表,因为 above.I 想要列出不相同的标题。
我尝试了很多不同的东西,但没有运气。
如何比较这些标题?
SELECT database1.table1.title as title1,database2.table2.title as title2
FROM database1.table1 JOIN database2.table2 ON (database1.table1.id =database2.table2)
WHERE database1.table1.title NOT LIKE database2.table2.title COLLATE utf8_general_ci
上述查询的结果:
Bienvenue Chez les Ch'tis, Bienvenue Chez les Ch'tis
XYZ, QWE
但我只想要下面的结果
XYZ、QWE
我想排除法文的,我想将其视为相同的标题。
’
是 ’
的 Mojibake。当以两种不同的方式存储 same 右单引号时,问题就来了。不是 COLLATION
问题。
首先,检查两个表以查看存储的内容:
SELECT HEX(title) FROM database1.table1 WHERE id = 1
您会发现的两种可能情况是:
C h ... t i s
43 68 E28099 74 69 73 -- correctly encoded with UTF-8
43 68 C3A2 E282AC E284A2 74 69 73 -- "double encoded"
(为清楚起见,我在 HEX 中添加了空格。)
如果其中一个表是 "doubly encoded",那么它在 INSERTing
期间被弄乱了。字符串将不比较相等。