SELECT id, title, keywords, post, img,
NULL as device_id, null as mfgr, null as model, null as img
FROM blog_posts WHERE MATCH(title, desc_meta, keywords_meta, post) AGAINST('boost')
UNION ALL
SELECT NULL, NULL, NULL, NULL, id AS device_id, mfgr, model, img, summary
FROM device_specs WHERE MATCH(mfgr, model, summary) AGAINST('boost');
考虑上面的查询,两个表没有任何共同之处。这仅用于搜索脚本。我将如何保持与两个组合表的相关性?上述查询有效,但在所有情况下,blog_posts
的结果都会显示在device_specs
的结果之前。
答案 0 :(得分:2)
您想要为每个子查询添加相关性。您可以在没有子查询的情况下执行此操作:
SELECT id, title, keywords, post, img,
NULL as device_id, null as mfgr, null as model, null as img,
MATCH(title, desc_meta, keywords_meta, post) AGAINST('boost') as relevance
FROM blog_posts
WHERE MATCH(title, desc_meta, keywords_meta, post) AGAINST('boost') > 0
UNION ALL
SELECT NULL, NULL, NULL, NULL, id AS device_id, mfgr, model, img, summary,
MATCH(mfgr, model, summary) AGAINST('boost') as relevance
FROM device_specs
WHERE MATCH(mfgr, model, summary) AGAINST('boost') > 0
ORDER BY relevance;