使用分页和分数在两个不同的表中搜索数据

时间:2011-10-26 01:13:14

标签: mysql search pagination full-text-search

我有两个不同的表

tbl_news(news_id, title, content)

tbl_packages(packaged_id, title, content)

如何在这些表中搜索得分和分页?

1 个答案:

答案 0 :(得分:0)

如果我了解你,你需要full text search

以下是代码,它可能对您有帮助。

SELECT id, title, content, link FROM (
SELECT news_id AS id, news_title AS title, news_description AS content, 
MATCH (news_description, news_title) AGAINST ('$keyword') AS relevance FROM tbl_news
UNION ALL
SELECT package_id AS id, package_title AS title, package_description AS content,
MATCH (package_description, package_title) AGAINST ('$keyword') AS relevance FROM tbl_packages
)temp_sort_table
WHERE relevance >0 ORDER BY relevance DESC LIMIT $offset,$limit