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

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -