1

I checked this answer Appending data to a MySQL database field that already has data in it

And that tells me how I can append data to a MySQL table, which is great. But I don't want to do it for certain tables. For example if it includes a couple of strings. Is that possible?

Ideally I want to run an SQL query to append the word "course" to my products in WooCommerce. But I don't want it to add it if the word "bundle" exists.

Eoin
  • 1,413
  • 2
  • 17
  • 32
  • 1
    You should narrow your question. There are 2 kinds of input check: client-side (done in client's UI) ans server-side (done on the server). Also, it is not obvious what kind of string you want to prohibit - add an example. – 0leg Mar 28 '18 at 15:30
  • @Oleg thank you so much for your feedback. I have updated my query, does that help or is there some way I can add more information? – Eoin Mar 28 '18 at 15:38

1 Answers1

2

You can use this SQL query:

UPDATE table_name
SET field_name = CONCAT_WS(' ', 'course', field_name) 
WHERE field_name NOT LIKE '%bundle%';

This will prefix all records that don't contain the word bundle with the word course.

0leg
  • 13,464
  • 16
  • 70
  • 94