I have mysql table as follow:
id host url
--------------------------------------
1 test.com/index.php
2 domain.com/list
3 www.stackoverflow.com/questions/ask
I need output as follow
id host url
------------------------------------------
1 test.com test.com/index.php
2 domain.com domain.com/list
3 stackoverflow.com www.stackoverflow.com/questions/ask
Thanks in advance.
Use SUBSTRING_INDEX(str, delim, count)
:
UPDATE tablename
SET host = SUBSTRING_INDEX(url, '/', 1);
This will make your table looks like:
| ID | HOST | URL |
--------------------------------------------------------------------
| 1 | test.com | test.com/index.php |
| 2 | domain.com | domain.com/list |
| 3 | www.stackoverflow.com | www.stackoverflow.com/questions/ask |
Assuming your table is named t
:
UPDATE t
SET host=SUBSTRING_INDEX(url, '/', 1);
UPDATE tbl1 SET host = SUBSTRING_INDEX(url, '/', 1)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.