我正在使用MySQL 5.5,这就是为什么我不能使用FULLTEXT搜索所以请不要建议它.
我想要做的是,如果用户我有5条记录,例如:
Amitesh
Ami
Amit
Abhi
Arun
Run Code Online (Sandbox Code Playgroud)
如果有人搜索Ami然后它应该首先返回Ami作为完全匹配然后Amit&Amitesh
Gor*_*off 20
你可以做:
select *
from table t
where col like '%Ami%'
order by (col = 'Ami') desc, length(col);
Run Code Online (Sandbox Code Playgroud)
小智 5
SELECT *
FROM table t
WHERE col LIKE '%Ami%'
ORDER BY INSTR(col,'Ami') asc, col asc;
Run Code Online (Sandbox Code Playgroud)