There’s an index table. (Links tags with ids).
REPLACE INTO com_index (word, ids) VALUES ('word1', concat(ids, ' 2')), ('word2', concat(ids, ' 2'))
word is a primary key.
I try to look through rows, add ‘ 2’ to ids in those of them, which exist; and create a new row with ‘ 2’ if it doesn’t.
So, I need to look if there’s any row with such word column (word1 or word2 …) and concat ‘ 2’ to thier ids. And if there is no such rows (with such word column) – create it with ids = ‘ 2’.
And it’s MySQL! (there’s no sub_selects)
A very simple solution that is possible because
wordis the primary key*:Make sure to check the MySQL Manual for the
INSERT ... ONsyntax*actually, it is also possible with other kinds of indexes, as long as they’re unique (which is given with a primary key