Gareth Burrows
Gareth Burrows

Reputation: 1182

mysql replacing all characters to left of specific character with a string

Is it possible in mysql to replace a character and all characters to the left with a string.

so if I have a table with

[email protected]
[email protected]

it becomes

www.abc.com
www.123.co.uk

afraid I have no idea where to begin :(

Upvotes: 1

Views: 58

Answers (2)

Gareth Burrows
Gareth Burrows

Reputation: 1182

I did it with

concat("www.",SUBSTRING_INDEX(e.email, '@', -1))

Upvotes: 0

Giorgos Betsos
Giorgos Betsos

Reputation: 72235

You can do:

UPDATE mytable
SET email = CONCAT('www.', SUBSTRING_INDEX(email, '@', -1))

Upvotes: 3

Related Questions