i wanted to ask, how is it in sql to search multiple tables with different column names for a given string ? i know for 1 table it's:
select * from table where column like '%string%'
... but for searching multiple tables (with different column names) for that same string ? i'm searching something like this:
select * from table1,table2 where table1.column and table2.column like '%string%'
so it would search in table1.column and table2.column for that specific string is it possible ?
This would be the typical way.
select * from table1,table2
where table1.column like '%string%'
OR table2.column like '%string%'
OR perhaps slightly more efficient
This will likely result in a slight performance gain as it doesn't have to "search twice" as the "OR" notation would have to. The overhead of the string concat is likely less than the overhead of doing a full table scan again. which %txt% will have to do.
select * from table1,table2
where concat(table1.column, table2.column) like '%string%'
Incidentally this is doing a cross join between tables... are you sure this is how the join should operate? usually there's a key relationship between them.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments