I am trying to first select data from a row which contains certain characters. I would then like to update and append new data into another row of those items that were selected. This is my current solution I came up with when trying to combine the two tasks into a single query.
SELECT *
FROM `parts`UPDATE `parts` SET
`keywords` = CONCAT(`keywords` , 'Phillips' )
WHERE INSTR(`name`, 'PHI') > 0
-
And ignore that there is no delimiter between the old keywords and 'Phillips'?Rick James– Rick James2016年02月20日 01:30:40 +00:00Commented Feb 20, 2016 at 1:30
1 Answer 1
You can make a SELECT as part of an UPDATE statement, but you can't make an UPDATE part of a SELECT statement. However, based on your example you don't need to, instead you can just do the following:
UPDATE parts
SET keywords = CONCAT(keywords,'Phillips')
WHERE name LIKE '%Phi%'
If you want to retrieve the results after you've updated them just execute the following afterwards:
SELECT *
FROM parts
WHERE name LIKE '%Phi%'