首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mysql多表全文搜索查询修改

问Mysql多表全文搜索查询修改
EN

Stack Overflow用户
提问于 2012-08-10 16:28:17
回答 1查看 854关注 0票数 0

我正在建立一个Mysql全文搜索,我有4个表搜索。当我在搜索查询中只使用一个表时,它可以工作,但当我在查询中使用多个表时,它不起作用。此外,我不想在查询中使用UNION ALL,因为我使用复选框选择选项在单个或多个表中执行搜索。

对多个表的MySQL查询不起作用。

代码语言:javascript
复制
$sqlquery = mysql_query("(SELECT * FROM table1, table2, table3, table4 WHERE MATCH (pflink, title) AGAINST ('%$keyword*%' IN BOOLEAN MODE) )ORDER by pflink desc, $orderby $sortby LIMIT $rowsperpage OFFSET $offset ")or die (mysql_error());

它给出了错误Column 'pflink' in where clause is ambiguous

使用单表查询是可行的。

代码语言:javascript
复制
$sqlquery = mysql_query("(SELECT * FROM table1 WHERE MATCH (pflink, title) AGAINST ('%$keyword*%' IN BOOLEAN MODE) )ORDER by pflink desc, $orderby $sortby LIMIT $rowsperpage OFFSET $offset ")or die (mysql_error());

Html复选框代码

代码语言:javascript
复制
  <input name="all-tables" type="checkbox" value="true" checked="checked" id="check-all" >
  <input name="table1" type="checkbox" value="true" disabled="disabled" >
  <input name="table2" type="checkbox" value="true" disabled="disabled" >
  <input name="table3" type="checkbox" value="true" disabled="disabled" >
  <input name="table4" type="checkbox" value="true" disabled="disabled" >

请建议任何可能的方法来修改此查询,使其适用于多个表。

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2012-08-10 16:55:14

很久以前,我也遇到过类似的情况。我有多个表可以使用全文,但我不知道如何做我想要的。我找了找,但找不到路。所以最后我想出了下面的想法

代码语言:javascript
复制
1. Make another table say "keywords", with fields title, description , item_id, and the table data belongs to.
2. make a code to fetch all title and description from table1,table2 and so on and insert it to keywords.
3. Make keywords table suitable for full text search.
4. when user searches, search keyword table. Retrieve relevant value from table1, table 2 etc from the recordset (as you get item id and table from the full text search query).

这样做的好处是查询将更快和更容易。

希望这能有所帮助

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11897969

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档