简体   繁体   English

MySQL不区分大小写的DISTINCT

[英]MySQL case-insensitive DISTINCT

Can anyone tell me how i can SELECT DISTINCT from my database without it being case-sensitive? 任何人都可以告诉我如何从我的数据库中选择DISTINCT而不区分大小写?

My query is 我的疑问是

SELECT DISTINCT email FROM `jm_order`

The results brings out all the emails in the table but repeats the ones with different cases. 结果显示表中的所有电子邮件,但重复具有不同情况的电子邮件。 This is expected because the values are different case wise. 这是预期的,因为值的情况不同。 eg 例如

sam@gmail.com
josh@gmail.com
Sam@gmail.com
john@gmail.com

But what i want is for the same emails, to be grouped together regardless of the case. 但我想要的是相同的电子邮件,无论如何都要组合在一起。 What adjustment can i make to my SQL to stop it from repeating for example sam@gmail.com and Sam@gmail.com just because they are different cases? 我可以对我的SQL进行哪些调整以阻止它重复例如sam@gmail.comSam@gmail.com ,因为它们是不同的情况?

Try to use upper function 尝试使用upper功能

SELECT DISTINCT UPPER(email) FROM `jm_order`

you can also use lower instead 你也可以使用lower代替

SELECT DISTINCT LOWER(email) FROM `jm_order`

More information . 更多信息

If you want to preserve the case of the email (so it actually matches one of the rows), you can do: 如果要保留电子邮件的大小写(因此它实际上与其中一行匹配),您可以执行以下操作:

select email
from jm_order
group by lower(email);

Try this: 尝试这个:

SELECT DISTINCT LOWER(email) AS email 
FROM `jm_order`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM