Aman Aman - 3 months ago 13x
MySQL Question

removing whitespaces not working MySQL. Used TRIM() and REPLACE()

Take a look : FIDDLE

select IF((TRIM(replace(' IKECHUKWU OSUJI',' ',''))=TRIM(replace('IKECHUKWU OSUJI','
select IF((TRIM(replace(' Aman Minhas ',' ',''))=TRIM(replace(' Aman Min has','

Err image
The first query returns diff. The second returns same. Its some weird spacing issue, cant seem to understand why this behaviour.


Your first string has a tab in it:

select IF((TRIM(replace(' IKECHUKWU  OSUJI',' ',''))
                                   ^ this is actually a tab in the Fiddle

You can get rid of it with an additional REPLACE:

REPLACE(REPLACE(myString, ' ', ''), '\t', '')

The \t is a special literal. Other special literals such as newline or ASCII NUL may impact you as well. Literals are listed here.