I have a table that contains words and an input field to search that table using a live search. Currently, I use the following query to search the table:
SELECT word FROM words WHERE word LIKE '%searchstring%' ORDER BY word ASC
Is there a way to order the results so that the ones where the string is found at the beginning of the word come first and those where the string appears later in the word come last?
An example: searching for 'hab' currently returns
- a lphabet
- h abit
- r ehab
but I'd like it this way:
- hab it (first because 'hab' is the beginning)
- alp hab et (second because 'hab' is in the middle of the word)
- re hab (last because 'hab' is at the end of the word)
or at least this way:
- hab it (first because 'hab' is the beginning)
- re hab (second because 'hab' starts at the third letter)
- alp hab et (last because 'hab' starts latest, at the fourth letter)
Would be great if anyone could help me out with this!