MySQL全文搜索多表

时间:2011-04-10 13:13:18

标签: php mysql full-text-search search-engine

我有两张桌子:

"product_info" table:
id     name           price
==========================
1      LG Monitor     $250


"product_detail_info" table:
id    product_info_id    detail_title    title_position      content
========================================================================
1     1                  Features        2                   bla bla bla
2     1                  Specification   1                   bla bla bla

如何将两个表数据链接在一起以便在mysql全文搜索中进行搜索,并将结果返回到“product_info”表中的产品名称?

感谢。

2 个答案:

答案 0 :(得分:2)

SELECT
  pi.name
FROM
  product_info pi
  INNER JOIN product_detail_info pdi ON pdi.product_info_id = pi.id
WHERE
  pdi.content MATCH <your condition>

答案 1 :(得分:1)

mysql全文搜索功能将提供您想要的内容 - http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html。您只需要为其正确设置表格。

SELECT product_info.name FROM product_info 
LEFT JOIN product_detail_info 
ON product_info.id = product_detail_info.product_info_id
WHERE MATCH ( content ) AGAINST ( your_search_string )