1

Let's say I have a table named table1 in a sqlite3 database (via python) with two columns named 'id' and 'string' and here are the three entries in the table:

   id                string
  'a'               'google'
  'b'               'apple'
  'c'            'application' 

so let's say I want all the rows with 'app' in them, so how would i do that? I'm looking for something like this:

SELECT * FROM table1 WHERE 'app' in string

which would in theory return the last 2 rows....

warvariuc
  • 57,116
  • 41
  • 173
  • 227
Anshu Dwibhashi
  • 4,617
  • 3
  • 28
  • 59

3 Answers3

0

You can use LIKE

SELECT * FROM table1 
WHERE string LIKE '%app%'

DEMO

UPDATE:

When you use a front wildcard (LIKE '%app%'), the performance will be roughly the same.

If you want string starting with app, then using LIKE 'app%' would be better. Here's the reason :-

The part before the first wildcard serves as an access predicate, that is, they limit the scanned index range. The remaining characters do not narrow the scanned index range—non-matching entries are just left out of the result.

Anish Shah
  • 7,669
  • 8
  • 29
  • 40
0

Try this:

SELECT * FROM table1 WHERE string LIKE '%app%'
Raging Bull
  • 18,593
  • 13
  • 50
  • 55
0

It's very simple. You need to use the LIKE '%' operator in SQL. It's for string matching.

Your query should be something like this:

SELECT * FROM table1
WHERE string LIKE '%app%'

Since you didn't mention whether 'app' should be positioned at the beginning of string or the end, I've wrapped the string 'app' around two '%', so that it will locate the 'app' string anywhere inside string.