SQL在多个表上使用匹配(带连接)

时间:2014-03-11 10:44:44

标签: sql

mysql_query("SELECT a.about,b.title,b.article,b.description

FROM about a 
JOIN articles b ON b.user_id=a.user_id

WHERE MATCH(b.title,b.article) AGAINST ('$search')

");

这会产生错误“无法找到与列列表匹配的FULLTEXT索引”

但其中任何一个都可行......

mysql_query("SELECT a.about,b.title,b.article,b.description

FROM about a 
JOIN articles b ON b.user_id=a.user_id

WHERE MATCH(b.title) AGAINST ('$search')

");



mysql_query("SELECT a.about,b.title,b.article,b.description

FROM about a 
JOIN articles b ON b.user_id=a.user_id

WHERE MATCH(b.article) AGAINST ('$search')

");

在已声明的所有列上激活文本索引。

1 个答案:

答案 0 :(得分:1)

b.title,b.article上没有FULLTEXT索引。

将您的查询用作

mysql_query("SELECT a.about,b.title,b.article,b.description

FROM about a 
JOIN articles b ON b.user_id=a.user_id

WHERE MATCH(b.title) AGAINST ('$search')
and
MATCH(b.article) AGAINST ('$search')

");

或在b.title,b.article

上构建索引
CREATE FULLTEXT INDEX t_a_articles_index ON articles (title, article) ...

How create index in MySQL