You can use the SUBSTR()
function:
UPDATE your_table
SET product_item_short = SUBSTR(product_item_short, 6),
product_item_long = SUBSTR(product_item_long, 6);
Test case:
CREATE TABLE your_table (
id int,
product_item_short varchar(50),
product_item_long varchar(50)
);
INSERT INTO your_table VALUES (1, 'data/image/someimage.png', 'data/image/someimage.png');
INSERT INTO your_table VALUES (2, 'data/other-folder/someimage.png', 'data/other-folder/someimage.png');
INSERT INTO your_table VALUES (3, 'data/no-folder.png', 'data/no-folder.png');
INSERT INTO your_table VALUES (4, 'data/image/path/three-levels.png', 'data/image/path/three-levels.png');
Result after UPDATE
:
SELECT * FROM your_table;
+------+-----------------------------+-----------------------------+
| id | product_item_short | product_item_long |
+------+-----------------------------+-----------------------------+
| 1 | image/someimage.png | image/someimage.png |
| 2 | other-folder/someimage.png | other-folder/someimage.png |
| 3 | no-folder.png | no-folder.png |
| 4 | image/path/three-levels.png | image/path/three-levels.png |
+------+-----------------------------+-----------------------------+
4 rows in set (0.00 sec)
UPDATE:
If you a solution that eliminates the first directory of the path, whether it is data/
or anything-else/
, you may want to use the LOCATE()
function, as @Frank's suggested in another answer:
UPDATE your_table
SET product_item_short = SUBSTR(product_item_short, LOCATE('/', product_item_short) + 1),
product_item_long = SUBSTR(product_item_long, LOCATE('/', product_item_long) + 1);