cj333
cj333

Reputation: 2609

mysql multi-table fulltext query problem?

I am making a multi-table fulltext query.But I met some question. I need make a query like

(SELECT 
title,content,date,cat 
FROM article1 
WHERE 
cat='Science fiction' 
AND 
MATCH (title,content) 
AGAINST 
('+Harry +Potter' IN BOOLEAN MODE)) 
UNION 
(SELECT 
title,content,date 
FROM article3 
WHERE MATCH (title,content)
 AGAINST 
('+Harry +Potter' IN BOOLEAN MODE)) 
Order By date DESC LIMIT 10

But it caused Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

If I deleted cat='Science fiction' AND it can pass the test.

Where is the problem? If I want make a query what I want: first fulltext query require need meet cat='Science fiction'. Thanks a lot.

Upvotes: 3

Views: 135

Answers (4)

Doug T.
Doug T.

Reputation: 65599

Did mysql_query return FALSE, indicating a problem parsing your query? If you blindly passed "FALSE" into mysql_fetch_array(), I'd expect to see that kind of error.

Upvotes: 2

dnagirl
dnagirl

Reputation: 20456

I don't know why removing the cat LIKE 'Science fiction' makes the query work. As written, it should not work in either case. UNION requires both parts of the queries to produce the same number of columns with compatible types. Your UNION has 4 columns in the first part and 3 columns in the second:

SELECT  title, content, date, cat FROM article1  
UNION
SELECT  title, content, date      FROM article3

Upvotes: 2

Joe Stefanelli
Joe Stefanelli

Reputation: 135808

You are trying to UNION together result sets that return a different number of columns. Your first query returns 4 columns (title,content,date,cat) while your second only returns 3 (title,content,date). Each query must return the same number of columns.

Upvotes: 2

Scherbius.com
Scherbius.com

Reputation: 3414

try

cat LIKE 'Science fiction' 

Upvotes: 0

Related Questions