I want to add "/invent" at the beginning of the file path in the invImage and invThumbnail columns.
This is what I have in mind,
SELECT FROM inventory
SELECT CONCAT("/invent")
AS invImage, invThumbnail;
Since it is not easy to undo mistakes in SQL, a confirmation of my potential solution will be helpful.
2
Answers
Your current version will overwrite the value in the
invImage
column, but your stated goal is toa) prepend the string to the existing value, and
b) do this in two columns, not just one
WHERE invImage = "/images";
also won’t match any of the rows, because none of them contain exactly that value. I’ll assume you want to update all rows whoseinvImage
value starts with "/images".Therefore, try this:
My suggestion: add temporarily two columns to the table:
tmp_invImage
andtmp_invThumbnail
.Then run the query:
After the update, look if the values of
tmp_invImage
andtmp_invThumbnail
are correct.Then update the original columns:
and delete the
tmp_
columns.