Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to search for a substring in SQLite?

Whats the most efficient way to search for a sub string in SQLite?

I'm looking at the LIKE operator.

Do I have the right idea? Has this worked well for you?

http://www.sqlite.org/lang_expr.html

Thank You.

like image 541
T.T.T. Avatar asked Sep 08 '10 20:09

T.T.T.


People also ask

What is Substr in SQLite?

The SQLite substr function returns a substring from a string starting at a specified position with a predefined length.

How do I use wildcards in SQLite?

SQLite LIKE examplesTo find the tracks whose names start with the Wild literal string, you use the percent sign % wildcard at the end of the pattern. To find the tracks whose names end with Wild word, you use % wildcard at the beginning of the pattern.

How do I find data in SQLite?

To Search for the values define edit text and implement text watcher in database enter a query as shown below: editText. addTextChangedListener(new TextWatcher(){ Cursor cusror; cursor=db. rawQuery("SELECT * FROM "+ DB_NAME + " WHERE " + DB_NAME.id + " = " + DB_NAME.Id + " AND " + DB_NAME.

How do I reverse a string in SQLite?

Using a common table expression it is possible to reverse a string in SQLite. WITH reverse(i, c) AS ( values(-1, '') UNION ALL SELECT i-1, substr('dlrow olleh', i, 1) AS r FROM reverse WHERE r!= '' ) SELECT group_concat(c, '') AS reversed FROM reverse; Returns hello world .


2 Answers

Yepper, use Like. Select id from sometable where name like '%omm%' would return any row that had 'omm' anywhere in the name column.

like image 175
GrandmasterB Avatar answered Sep 27 '22 22:09

GrandmasterB


You can use LIKE, but it gets really slow if the pattern you're searching for starts with '%' -- i.e., if the substring you're looking for isn't necessarily at the beginning of the field.

If you need to do such searches, consider using FTS3, which makes full-text searching considerably more efficient.

like image 42
Jerry Coffin Avatar answered Sep 28 '22 00:09

Jerry Coffin