Yue_Hong
Yue_Hong

Reputation: 3

MySQL Fulltext Search on Multi Tables

I have 2 tables:

"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

How can I link both 2 tables data together for searching in mysql fulltext search and have the result returned to be the name of the product on "product_info" table?

Thanks.

Upvotes: 0

Views: 935

Answers (2)

David Gillen
David Gillen

Reputation: 1172

The mysql full text search functionality will give what you want - http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html. You'll just need to have your table set up correctly for it.

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 )

Upvotes: 1

GolezTrol
GolezTrol

Reputation: 116110

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>

Upvotes: 2

Related Questions