I am doing an autocomplete that makes a request to a url, which in turn queries the database.
This query is done with LIKE
. I use %$termo%
to be able to query, however I would like to sort the result according to the relevance of LIKE
, not alphabetically.
How can I do this?
Example: When querying car
, the order looks something like this:
SELECT * FROM tabela WHERE campo LIKE '%car%' ORDER BY aqui_vem_a_magica();
- carr or
- car or
- refor car
- colo car
That is the order not in alphabetical order, but because of the proximity of the characters that are at the beginning of the word ...