MySQL SELECT DISTINCT should be case sensitive?

前端 未结 3 508
旧巷少年郎
旧巷少年郎 2021-02-05 14:49

How do I make MySQL\'s SELECT DISTINCT case sensitive?

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


        
3条回答
  •  你的背包
    2021-02-05 14:59

    You can use a hashing function (MD5) and then group on that.

    SELECT Distinct(MD5(Cat)), Cat FROM (
      SELECT 'Cat'
        UNION ALL
      SELECT 'cat'
    ) AS BOW
    

    SQL Output:

提交回复
热议问题