MySQL SELECT DISTINCT应该区分大小写?

如何使MySQL的SELECT DISTINCT区分大小写?

create temporary table X (name varchar(50) NULL);
insert into X values ('this'), ('This');

现在这个查询:

select distinct(name) from X;

结果是:

this

这里发生了什么?我想SELECT DISTINCT区分大小写.那不应该是默认的吗?

解决方法:

使用BINARY operator

SELECT DISTINCT(BINARY name) AS Name FROM X;

你也可以选择CAST吧:

SELECT DISTINCT 
(CAST(name AS CHAR CHARACTER SET utf8) COLLATE utf8_bin) AS Name FROM X;

SQLFiddle

上一篇:SPOJ694 Distinct Substrings


下一篇:3D,点云分割,不要割个寂寞