I am trying to order my mysql queries based on the first letter but every method I have used is restricting my search.
我试图根据第一个字母来命令我的mysql查询,但我使用的每个方法都限制了我的搜索。
Example MySQL table Value computer services abc computer services dynamic computer services
示例MySQL表值计算机服务abc计算机服务动态计算机服务
If I search for computer services
I want the results to returned as:
如果我搜索计算机服务,我希望结果返回为:
**Name**
computer services
abc computer services
dynamic computer services
I am using mysql fullsearch text but if i use name LIKE 'c%'
I don't the other two results e.g.
我正在使用mysql fullsearch文本但是如果我使用名称LIKE'c%'我没有其他两个结果,例如
SELECT name FROM table WHERE match('name') against('computer services*' IN BOOLEAN MODE) AND name LIKE 'c%';
This would only return
这只会回来
- computer services
But I want it to return:
但我希望它回归:
- computer services
- abc computer services
- dynamic computer services
abc电脑服务
动态计算机服务
I am new to mysql full search text.
我是mysql全搜索文本的新手。
1 个解决方案
#1
2
Use an order by clause that matches the 'starts with' case first. I'm using not like
here because the boolean returns 0 or 1 and we want to reverse that to match the starts with case first.
使用与首先匹配'starts with'案例的order by子句。我在这里使用不像因为boolean返回0或1而我们想要反转它以匹配首先出现的情况。
SELECT name
FROM table
WHERE match('name') against('computer services*' IN BOOLEAN MODE)
ORDER BY name NOT LIKE 'computer services%', name;
#1
2
Use an order by clause that matches the 'starts with' case first. I'm using not like
here because the boolean returns 0 or 1 and we want to reverse that to match the starts with case first.
使用与首先匹配'starts with'案例的order by子句。我在这里使用不像因为boolean返回0或1而我们想要反转它以匹配首先出现的情况。
SELECT name
FROM table
WHERE match('name') against('computer services*' IN BOOLEAN MODE)
ORDER BY name NOT LIKE 'computer services%', name;