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

时间:2008-12-26 17:44:54

标签: mysql string-search

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

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

SELECT * FROM users, accounts, something_else WHERE ->ANY COLUMN CONTAINS 'this_string'<-

提前为SO社区提供

1 个答案:

答案 0 :(得分:29)

fulltext indexes添加到所有这些表中的所有字符串列,然后将结果联合起来

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')
...