你也可以在一個領域做到這一點。
MariaDB []> SELECT
-> concat_ws(', ',
-> IF(field1 LIKE '%keyword%','field1',NULL),
-> IF(field2 LIKE '%keyword%','field2',NULL),
-> IF(field3 LIKE '%keyword%','field3',NULL)
-> ) AS found_in, s.*
-> FROM searchtable s
-> WHERE field1 LIKE '%keyword%'
-> OR field1 LIKE '%keyword%'
-> OR field1 LIKE '%keyword%';
+------------------------+----+---------+---------+---------+
| found_in | id | field1 | field2 | field3 |
+------------------------+----+---------+---------+---------+
| field1 | 1 | keyword | NULL | NULL |
| field1, field3 | 4 | keyword | NULL | keyword |
| field1, field2 | 6 | keyword | keyword | NULL |
| field1, field2, field3 | 7 | keyword | keyword | keyword |
+------------------------+----+---------+---------+---------+
4 rows in set (0.01 sec)
MariaDB []>
沒有直接關係,但您可能對FULLTEXT搜索感興趣 – Mihai