MySQL Tips & Tricks

Saturday, August 2, 2008

Updating Data Strings with Concat

I needed to prefix http:// before any urls that didn't already have it.


update tbl_password set url=concat('http://',url) where url not like 'http://%';

(the following is my test statement which I used to avoid the risk of destroying data, by limiting it to one record)

update tbl_password set url=concat('http://',url) where url not like 'http://%' and url like '%supanames%';

Alternatively limit change to one record with 'limit'

update tbl_password set url=concat('http://',url) where url not like
'http://%' limit 1;

Labels:

0 Comments:

Post a Comment



<< Home