Please help me with this query. I am trying to replace a part of the string in one column with part of a string from another column the table should look like
image_url | video_url
----------------------------------------------------------------------------------------------
https://siteurl/folder/folder/folder/ | https://siteurl/folder/folder/folder/
folder/folder/folder/xyz.jpg | folder/folder/folder/folder/xyz.mp4
I am trying to update the folder path of the video_url with the one from the image url.The folders manes are all completely different on different rows I have tried the below but this throws an error
UPDATE `tbl`
set video_url = REPLACE(video_url,
SELECT SUBSTRING_INDEX(video_url, "/", 10),
SELECT SUBSTRING_INDEX(image_url, "/", 9))
where image_url like '%ch1%'
I anyone can provide a solution it would be great help
Not sure if it is what you want but try this:
UPDATE Table
SET video_url =
CONCAT(
LEFT(image_url, LENGTH(image_url) - LOCATE('/', REVERSE(image_url))),
'/',
SUBSTRING_INDEX(video_url, '/', -1)
);
This will replace the folders path on video_url column with the folders path from image_url column.
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.