MySQL:如何在多个表中搜索任何列中存在的字符串 [英] MySQL: How to search multiple tables for a string existing in any column
本文介绍了MySQL:如何在多个表中搜索任何列中存在的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何在table_a table_b table_c
中搜索,该字符串的列数是随机的?
How can I search for in table_a table_b table_c
, which have a random number of columns for a string?
我知道这不是正确的sql,但是会是这样的:
I know this is not proper sql but it would be something like:
SELECT * FROM users, accounts, something_else WHERE ->ANY COLUMN CONTAINS 'this_string'<-
提前为SO社区
推荐答案
添加全文索引至所有这些表中的所有字符串列,然后合并结果
Add fulltext indexes to all of the string columns in all of those tables, then union the results
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')
...
这篇关于MySQL:如何在多个表中搜索任何列中存在的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文