I'm trying to fill a column a.total
with the number of occurrences of a.name
in b.content
.
a b
+--------------+ +----------------------+
| name | total | | content |
+------+-------+ +----------------------+
| foo | 3 | | hello bar |
| bar | 4 | | hola foofoo |
+--------------+ | nihao foo, bye bar |
| et bar se bar |
+----------------------+
I tried the command below:
UPDATE a SET a.total = (SELECT COUNT(*) FROM b WHERE b.content LIKE CONCAT('%', a.name, '%') );
But I get this:
Query OK, 0 rows affected (0.16 sec)
Rows matched: 4321 Changed: 0 Warnings: 0" with my command
What's wrong in this command ? And how can I also take into account all occurrences of foo
and bar
in a same content
row ?