Mysql: Order by like?
Solution 1:
order by case
when name LIKE "%John%" then 1
when name LIKE "%Doe%" then 2
else 3
end
Solution 2:
To build on RedFilter's answer, you could make the rows that have both keywords to be at the top:
order by case
when (name LIKE "%John%" and name LIKE "%Doe%") then 1
when name LIKE "%John%" then 2
when name LIKE "%Doe%" then 3
end
Solution 3:
Read up on Boolean Fulltext Searches, with which you can do ordering.