MySQL:如何在多个表中搜索任何列中存在的字符串

fms*_*msf 10 mysql string-search

如何搜索in table_a table_b table_c,其中包含字符串的随机列数?

我知道这不是正确的sql但它会是这样的:

SELECT * FROM users, accounts, something_else WHERE ->ANY COLUMN CONTAINS 'this_string'<-
Run Code Online (Sandbox Code Playgroud)

Ty提前为SO社区

ʞɔı*_*ɔıu 29

全文索引添加到所有这些表中的所有字符串列,然后将结果合并

select * from table1 where match(col1, col2, col3) against ('some string')
union all
select * from table2 where match(col1, col2) against ('some string')
union all
select * from table3 where match(col1, col2, col3, col4) against ('some string')
...
Run Code Online (Sandbox Code Playgroud)