Forum Moderators: open

Message Too Old, No Replies

Multiple Tables Query using MySQL and Matching

         

username

5:45 pm on Apr 27, 2008 (gmt 0)

10+ Year Member Top Contributors Of The Month



Hi all, I have the following query which works totally fine on one single table that I am querying.

$query = "SELECT *, MATCH(title, article) AGAINST ('$searchString') AS score FROM tbl_articles_test WHERE MATCH(title, article) AGAINST('$searchString');

However, I need the query to run across a few tables at once, all of which have the same structure, but have been broken up for good data management due the content type. So I need the above query to check tbl_articles_test2, tbl_articles_test3 etc as part of the query.

Previously I have used UNION ALL to do things like this, but it does not seem to work with the above query? Can someone please help?

Thanks in advance.

username

5:11 pm on Apr 28, 2008 (gmt 0)

10+ Year Member Top Contributors Of The Month



So, just checking in, does anyone have any ideas as to how to handle this query?

Demaestro

5:15 pm on Apr 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



SELECT *, MATCH(title, article) AGAINST ('$searchString') AS score FROM tbl_articles_test WHERE MATCH(title, article) AGAINST('$searchString')

UNION ALL

SELECT *, MATCH(title, article) AGAINST ('$searchString') AS score FROM tbl_articles_test2 WHERE MATCH(title, article) AGAINST('$searchString')

UNION ALL

SELECT *, MATCH(title, article) AGAINST ('$searchString') AS score FROM tbl_articles_test3 WHERE MATCH(title, article) AGAINST('$searchString')

username

6:24 pm on Apr 28, 2008 (gmt 0)

10+ Year Member Top Contributors Of The Month



Thanks anyway guys. Turns out that my FULLTEXT Keys needed to be defined in the one key. The query Demaestro had was what I originally tried and wasn't the problem. I needed to make sure my database fields I was searching on were defined as FULLTEXT keys. They strangely needed to be defined under the one key not separate keys which was causing the issue. Would like to know why?