I have a table named testlink and it has url and newtarget columns.
I would like to take the string expressions https://domain1.com/
here in the url column and change all the data in the newtarget
column to https://domain1.com/search/?q=
pulled string expression.
So briefly;
url columns from https://domain1.com/topic1
will be changed to https://domain1.com/search/?q=topic1
in the newtarget
column
There are about 6 thousand different topics (lines) available.
Database: Mysql / Phpmyadmin.
3
Answers
use REPLACE
If you want to conditionally change the value, you can use string manipulations:
This uses
substring_index()
to get the last part of the string (after the last/
). It usesleft()
to get the first part (based on the length of the last part) and then concatenates the values you want.Of course, test this logic using a
SELECT
before implementing anUPDATE
.If you’re using MySQL 8, then you’d be able to do that with REGEXP_REPLACE.
For your example, this should work :