sql - Android : Nearest match query from SQLite DB if input string value is bigger than any of the DB values? -
i have db entries: james andy bob david
for input string "bobby" want return 'bob' row. or input string "candy" want return 'andy' row.
i using android cursors can run raw query.
you might want try this:
select name names name '%andy%' or 'andy' ('%' || name || '%') order abs(length('andy') - length(name)), name limit 1
it select shortest match containing string "andy" or longest match contained within "andy", using alphabetical order tiebreaker. all rows remove limit clause.
Comments
Post a Comment