开发者

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 tes开发者_如何转开发t.

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.


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.


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


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.


try

cat LIKE 'Science fiction' 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜