Pergunta

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?

Foi útil?

Solução

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.

Outras dicas

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`
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top