MYSQL testing string field contains another altered string field I have this table : 

mysql&gt; desc mytab;
+------------+-------------+------+-----+---------+----------------+
| Field      | Type        | Null | Key | Default | Extra          |
+------------+-------------+------+-----+---------+----------------+
| id         | int(11)     | NO   | PRI | NULL    | auto_increment |
| value      | varchar(50) | YES  |     | NULL    |                |
| template   | varchar(50) | YES  |     | NULL    |                |
| difference | tinyint(1)  | YES  |     | NULL    |                |
+------------+-------------+------+-----+---------+----------------+


containing this sample data : 

mysql&gt; select * from mytab;
+----+-------+----------------+------------+
| id | value | template       | difference |
+----+-------+----------------+------------+
|  1 | 7     | |2|5|7|8|9|12| |       NULL |
|  2 | 0     | |5|            |       NULL |
|  3 | 5     | |2|5|7|8|9|12| |       NULL |
+----+-------+----------------+------------+
3 rows in set (0.00 sec)


I want to set difference field to FALSE if template contains '|value|' and to TRUE if not.

so the result would be :

mysql&gt; select * from mytab;
+----+-------+----------------+------------+
| id | value | template       | difference |
+----+-------+----------------+------------+
|  1 | 7     | |2|5|7|8|9|12| |       0    |
|  2 | 0     | |5|            |       1    |
|  3 | 5     | |2|5|7|8|9|12| |       0    |
+----+-------+----------------+------------+
3 rows in set (0.00 sec)
I found this solution : 

mysql&gt; update mytab set difference=(template not like concat('%|',value,'|%'));
Query OK, 0 rows affected (0.05 sec)
Rows matched: 3  Changed: 0  Warnings: 0

mysql&gt; select * from  mytab;
+----+-------+----------------+------------+
| id | value | template       | difference |
+----+-------+----------------+------------+
|  1 | 7     | |2|5|7|8|9|12| |          0 |
|  2 | 0     | |5|            |          1 |
|  3 | 5     | |2|5|7|8|9|12| |          0 |
+----+-------+----------------+------------+
3 rows in set (0.00 


sec)