Q:

Mysql LIKE Order Bu Exact Match

I have a query that gets information using the LIKE
SELECT * FROM table WHERE column LIKE '%$search%'

Now if i search for "Hello there" it will return something like
Oh hello there
Hello there
Hello there how are you

But i want to sort it by exact match first so it should be like
Hello there
Hello there how are you
Oh hello there

With the exact match on top and the exact match at the start of the sentence after that 

A:

try this
    SELECT * FROM table1 WHERE column LIKE '%$search%'
    order by case when column like '$search%'  then 1        //hello in begining
                  when column like '%$search%' then 2        //hello in middle
                  when column like '%$search'  then 3 end    //hello in end

watch demo here

A:

Use INSTR to order the result by the position of the search string in the column:;
SELECT * FROM table 
WHERE column LIKE '%$search%'
order by INSTR(column, '$search')

