MySQL Where RLIKE 句子中的任意单词

MySQL Where RLIKE any word of sentence

我有一个 table 这样的:

+-------------+-------------------+----------------+
|id           | column1           | column2        |
+-------------+-------------------+----------------+
| 1           | apple iphone 6s   | iphone         |
| 2           | iphone apple 5    | apple iphone   |
| 3           | iphone 4          | samsung        |
| 4           | iphone 4          | apple iphone 6 |
+-------------+-------------------+----------------+

如何使用 rlike 语句 return 列 1 的任何单词包含在列 2 中的所有记录? (在本例中 id=1,2,4)

谢谢

试试这个:

SELECT * FROM tbl WHERE column2 RLIKE REPLACE(column1, ' ', '|')

REPLACE 将所有出现的“ ”替换为“|”,这实质上创建了一个正则表达式,该正则表达式匹配包含 column1 中任何 space 分隔词的字符串(例如 "apple|iphone|6s").