Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL: Copy from column to another column with replace space

Tags:

php

mysql

I have table in my DataBase like this:-

ID       Name              Url         Date
11   News title test2               22-10-2014
12   News title test3               22-10-2014
13   News title test4               22-10-2014

Now I need to copy the value from Name to Url and replace the space to -

So, The table must be like after copy :-

ID       Name                     Url                    Date
11   News title test2       News-title-test2           22-10-2014
12   News title test3       News-title-test2           22-10-2014
13   News title test4       News-title-test2           22-10-2014

Are there way to do that by SQL or PHP

like image 307
house itexpert Avatar asked Apr 16 '26 18:04

house itexpert


1 Answers

Simply update the table and use the REPLACE() function

UPDATE table
SET Url = REPLACE(Name,' ', '-')
like image 124
waka Avatar answered Apr 18 '26 08:04

waka