I have a a table “wordlist”, with a score attributed to each word: either 1 or -1:
id | name | val
1, 'hello', 1,
2, 'world', -1
3, 'test', 1,
...
I also have a table “texts” containing texts:
id | text | score
1, 'hello world', 0
2, 'Lorem Ipsum Dolor Sit Amet...', 0
...
I’d like to update the field “score” from the table “texts” with this rule:
score = sum(wordlist.val) where each word of the sentence is present in the wordlist.
I tried this way, but it’s not working:
update texts as t set score=(select sum(val) from wordlist where word in (concat('\'', replace(t.text,' ','\',\''),'\'')))
I have more than 500K lines of data to process, so I’d rather use only MySQL, without using any PHP.
Thanks in advance if you have a solution!
I wish there was an explode() function in MySQL!
You could use FIND_IN_SET(), like this:
if you need to update your table, you could use this: