문제

Can anyone tell me how i can SELECT DISTINCT from my database without it being case-sensitive?

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. e.g

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?

도움이 되었습니까?

해결책

Try to use upper function

SELECT DISTINCT UPPER(email) FROM `jm_order`

you can also use lower instead

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 ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top