Is it possible to write two “from” clauses in a select statement, so that the search queries two tables? Or, do I need a join statement in here?
The submitted form in html has two text input boxes for keywords. I want each input box to search different tables.
My example:
"SELECT * FROM table_1 WHERE MATCH(column) AGAINST("word_1" IN BOOLEAN MODE)
AND SELECT * FROM table_2 WHERE MATCH(column) AGAINST("word_2" IN BOOLEAN MODE)"
(SELECT * FROM table_1 WHERE MATCH(column) AGAINST("word_1*" IN BOOLEAN MODE))
UNION
(SELECT * FROM table_2 WHERE MATCH(column) AGAINST("word_2*" IN BOOLEAN MODE))
I am assuming that this will work for full-text searching (?).
Both SELECTs must return the same number of columns as well (I know that this is implicit in your ‘same type’ rule, but it can’t hurt saying it explicitly )
The best thing is not to use ‘*’, but name each column. That way, if for some reason in the future a column is added to one of the tables, the UNION will continue to work.