MYSQL How to use trim in select query
my table have set of re开发者_运维问答cords around 50,
in the table i have column called USERNAME
, but some of username leading and trailing have the white space ,
so am not getting exact order result because of white space,
So tell me how to use the trim in SELECT
query ,
Thanks
You can use TRIM in the ORDER BY:
ORDER BY TRIM(username)
...but this will only trim excess space on the left and right side of the text, not in between.
Using TRIM in the SELECT is as easy as:
SELECT TRIM(username) AS username
FROM your_table
You can use REPLACE in your query to remove all whitespaces from strings, e.g.:
SELECT REPLACE(A.Postal, ' ', '') AS Postal FROM ADDRESS
Be aware that this will remove all whitespaces, not only the leading and tailing ones.
精彩评论