Search code examples
iossqlobjective-csqlitefmdb

Return filtered LIKE results in SQLite using FMDB


Using SQLite is there a way of using the LIKE command where the search parameter could find results that would be considered a substring of itself

ie. a search parameter of "delicious and tasty fruit and cinnamon." could return "delicious and tasty" in a DESC order by length so that if delicious was also a returned result it would show up last.

searching for "delicious and tasty fruit and cinnamon." could return...

 delicious and tasty fruit
 delicious and tasty
 delicious

Solution

  • You don't need LIKE for that:

    SELECT * FROM [foo]
    WHERE a = substr('delicious and tasty fruit and cinnamona', 1, length(a))
    ORDER BY length(a) DESC