Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove white space from concatenated string fields in MySQL

I have 3 fields I am concatenating and it's working just fine in my query, but I cannot resolve how to remove the whitespace from the merged data in the concat field.

TRIM(CONCAT(c.data1,c.data2)) AS concat_done

Result:

concat_done
33 0250S 0450E 028NW
like image 274
OldWest Avatar asked Dec 13 '22 04:12

OldWest


2 Answers

instead of

TRIM(CONCAT(c.data1,c.data2)) AS concat_done

try

REPLACE(CONCAT(c.data1,c.data2), ' ', '') AS concat_done
like image 167
Chris Drappier Avatar answered Feb 01 '23 23:02

Chris Drappier


add a REPLACE call:

REPLACE(TRIM(etc...), ' ', '')
                       ^--one space
                            ^-- no spaces
like image 41
Marc B Avatar answered Feb 02 '23 01:02

Marc B