0

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 Feb 20 '16 at 1:30
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%'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.