How to use MySQL, as with order, with exact match

I'm using MySQL 5.5, so why can't I use FULLTEXT search, so please don't suggest it.

What I wanted to do is if the user has 5 records, for example:

Amitesh
Ami
Amit
Abhi
Arun

      

and if someone is looking for Ami, then he must return Ami first as an exact match, then Amit and Amiteh

+12


source to share


2 answers


You can do:



select *
from table t
where col like '%Ami%'
order by (col = 'Ami') desc, length(col);

      

+17


source


SELECT *
FROM table t
WHERE col LIKE '%Ami%'
ORDER BY INSTR(col,'Ami') asc, col asc;

      



0


source







All Articles