Reputation: 1608
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.
Upvotes: 0
Views: 891
Reputation: 18569
Use SUBSTRING_INDEX
UPDATE tbl1 SET host = SUBSTRING_INDEX(url, '/', 1)
Upvotes: 0
Reputation: 79899
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 |
Upvotes: 4
Reputation: 13890
Assuming your table is named t
:
UPDATE t
SET host=SUBSTRING_INDEX(url, '/', 1);
Upvotes: 2