在2个以上具有不同数据的表中进行全文搜索
你好,我有这个sql语句
SELECT *, MATCH (first_name,last_name) AGAINST ('*?*' IN BOOLEAN MODE) AS score, MATCH (groups.groupname) AGAINST ('*?*' IN BOOLEAN MODE) AS sscore
FROM users INNER JOIN groups
WHERE MATCH (first_name,last_name) AGAINST ('*?*' IN BOOLEAN MODE) OR MATCH (groups.groupname) AGAINST ('*?*' IN BOOLEAN MODE)
ORDER BY 'score' Desc
1)我如何按联合分数排序?我的意思是,使用这个 sql 语句,它会为第一场比赛创建一个分数,并为第二场比赛创建一个分数。我如何将这两个分数相加并按该分数排序?
2)我也知道,由于数据不一样,INNER JOIN 方式不是最好的。我可以删除它吗?
最后,如果我在使用例如sim时删除IN BOOLEAN MODE并且first_name是simos,我不会得到结果。事实上,在布尔模式下,如果我输入 sim,我会得到一个空结果集,我将得到 simos 作为结果。
编辑:我通过做这个
(SELECT `id`,MATCH(first_name,last_name) AGAINST ('?*' IN BOOLEAN MODE) AS score FROM `users` WHERE MATCH(first_name,last_name) AGAINST ('?*' IN BOOLEAN MODE))
联盟 回答了我的第二个问题 (SELECT groupid
, MATCH(groupname) AGAINST ('?') AS 分数 FROM groups
WHERE MATCH(groupname) AGAINST ('?') )
这虽然改变了一切,因为我不需要联合分数,但仍然有布尔模式的问题
Hi I have this sql statement
SELECT *, MATCH (first_name,last_name) AGAINST ('*?*' IN BOOLEAN MODE) AS score, MATCH (groups.groupname) AGAINST ('*?*' IN BOOLEAN MODE) AS sscore
FROM users INNER JOIN groups
WHERE MATCH (first_name,last_name) AGAINST ('*?*' IN BOOLEAN MODE) OR MATCH (groups.groupname) AGAINST ('*?*' IN BOOLEAN MODE)
ORDER BY 'score' Desc
1) How can I ORDER by the joint score? I mean with this sql statement, it creates a score for the first match and a score for the second. How can I add those two scores and order by that score?
2) Also I know since the data are not the same the INNER JOIN way is not the best. is there anyway I can remove it?
and lastly, if i remove IN BOOLEAN MODE when i use for example sim and the first_name is simos I don't get the result. In fact I get an empty result set while in boolean mode if I put sim I'll get the simos as result.
EDIT: I responded my 2nd question by doing this
(SELECT `id`,MATCH(first_name,last_name) AGAINST ('?*' IN BOOLEAN MODE) AS score FROM `users` WHERE MATCH(first_name,last_name) AGAINST ('?*' IN BOOLEAN MODE))
union
(SELECT groupid
, MATCH(groupname) AGAINST ('?') AS score FROM groups
WHERE MATCH(groupname) AGAINST ('?') )
This though changes everything though as I don't need a joint score but still have the problem with the IN BOOLEAN MODE
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
order by 'score'
不正确,它将尝试按固定字符串score
' 进行排序,而不是您在match 中创建的别名...反对。
尝试
order by 'score'
is incorrect, it'll be trying to order by a fixed stringscore
', not the alias you created in thematch ... against
.Try