I have to update many records. I don't want to duplicate the entries. The table concatenates the value to the end. So in theory, I could add the value twice.

I want to put a check to make sure the entry is not already there; if it is, then skip the record.

update table1 
set value=concat(value,',test_data') 
where field1='abc';
  • 1
    Fix the list of doom and these sort of questions will be obvious. – danblack Sep 18 '18 at 22:43
UPDATE table1 
SET value=CONCAT(value, ',test_data') 
WHERE field1='abc'
  AND NOT INSTR(CONCAT(',',value,','), ',test_data,');

But I'd recommend to normalize your data structure... CSV data field is not safe.

  • Fails to handle start and end of string. Switch to FIND_IN_SET(). – Rick James Oct 7 '18 at 23:49
  • @RickJames ??? why? – Akina Oct 8 '18 at 5:09

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.