在mysql中使用搜索文本索引时出错

时间:2012-02-09 09:36:13

标签: php mysql

我有一张使用全文的表格

test1(id, name1, description1)
test2(id, name2, description2, test1_id)

和查询

Select a.name1, b.name2 From test1 as a, test2 as b 
Where a.id = b.test_1id 
And MATCH(a.name1, a.description1, b.name2, b.desciption2) AGAINST ("%searchstring%")

结果是mysql无法运行,我认为MATCH (...,b.name2, b.desciption2)中的错误,如何解决?谢谢!!

2 个答案:

答案 0 :(得分:0)

AGAINST ("%searchstring%")不应该是AGAINST ('%searchstring%')

将单引号替换为单引号...

以下是通常使用的查询

SELECT * FROM articles
WHERE MATCH(title, body) AGAINST ('PHP')

更新1

我发现您在Where a.id = b.test_1id

时遇到问题

我相信Where a.id = b.test_1id应为Where a.id = b.test1_id

在您的查询中,您有test_1id而不是test1_id。检查这是否是你的问题......

祝你好运!!!

答案 1 :(得分:0)

我认为你在where条件中有错误:

其中a.id = b.test_1.id (b是表test2的别名,但字段名称不应包含点)

将其更改为正确的字段名称,它应该有效。

相关问题