Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL: How to search multiple tables for a string existing in any column

How can I search for in table_a table_b table_c, which have a random number of columns for a string?

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

Ty in advance for SO community

like image 471
fmsf Avatar asked Dec 26 '08 17:12

fmsf


1 Answers

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')
...
like image 66
ʞɔıu Avatar answered Oct 15 '22 21:10

ʞɔıu