Jack The Baker
Jack The Baker

Reputation: 1883

Mysql query replace first empty string

I have many fields that contains extra space in start, like:

" RTX 3060"
-^

I want to remove first extra space from all fields of this table.

What I tried:

UPDATE table set field = concat( '', substring(field , 1)) where left(field ,1)=' ';

Return 0 result!

Upvotes: 0

Views: 293

Answers (2)

Alaindeseine
Alaindeseine

Reputation: 4423

Try with this statement, it will remove only the first space char of field is it's a space:

UPDATE `table` 
SET column = SUBSTRING(column,2)
WHERE SUBSTRING(column, 1, 1) = ' ';

Upvotes: 2

Mike
Mike

Reputation: 16

Try using the LTRIM function. The syntax looks something like this:

UPDATE table SET column = LTRIM(column);

Upvotes: 0

Related Questions