Reputation: 25733
my table have set of records 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
Upvotes: 24
Views: 64172
Reputation: 1030
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.
Upvotes: 3
Reputation: 332521
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
Upvotes: 35