MySQL, add a string in start of all column values

MySQL,  add a string  in start of all column values

Recently I come  to know a very cool function in mysql that is CONCAT.   There  is a table in mysql database known as tbl_clients.  Structure of this table is as follows:

tbl_clients

id int(11) auto_increment, P.K

client_name varchar(500)

. . . .

website varchar(500)

there were more than 500 clients having website homepage URLs and all URLs were without “http://”. like

www.abc.com

www.xyz.com

www.traveltoisland.com

So requirement was to add “http://” to every URL so it can be crawled by crawler.

So first solution to this is

UPDATE tbl_clients SET website =CONCAT('http://',website);

If there are some columns that already have “http://”  and we do not want to prepend “http://”  then we can do like this

UPDATE tbl_clients SET website=CONCAT('http://',website)
WHERE website NOT LIKE 'http://%';

 

 

Tags: