patternsqlMajor
Replace space (" ") with no space ("") in one column
Viewed 0 times
spacecolumnwithreplaceone
Problem
I have a table like this:
ID | Propinsi | Kota |
_________________________
1 | Aceh | Denpasar
2 | Aceh | Banda Aceh
3 | Sumatera | Asahan
This table has many rows. The problem is I want to replace the space before the text in column
ID | Propinsi | Kota |
_________________________
1 | Aceh |Denpasar
2 | Aceh |Banda Aceh
3 | Sumatera |Asahan
I searched Google, the function
Can someone fix my problem?
ID | Propinsi | Kota |
_________________________
1 | Aceh | Denpasar
2 | Aceh | Banda Aceh
3 | Sumatera | Asahan
This table has many rows. The problem is I want to replace the space before the text in column
Kota for all rows like this:ID | Propinsi | Kota |
_________________________
1 | Aceh |Denpasar
2 | Aceh |Banda Aceh
3 | Sumatera |Asahan
I searched Google, the function
replace in MySQL only affects one row:SELECT REPLACE(string_column, 'search', 'replace') as KotaCan someone fix my problem?
Solution
Try this:
To show without space:
To change your data:
If you want to remove only from the start you can use
To show without space:
select trim(kota) from yourtableTo change your data:
update yourtable set kota = trim(kota);TRIM function is different to REPLACE. REPLACE substitutes all occurrences of a string; TRIM removes only the spaces at the start and end of your string.If you want to remove only from the start you can use
LTRIM instead. For the end only you can use RTRIM.Code Snippets
select trim(kota) from yourtableupdate yourtable set kota = trim(kota);Context
StackExchange Database Administrators Q#54318, answer score: 20
Revisions (0)
No revisions yet.