SQLite Select from where column contains string?

Use LIKE clause. E.g. if your string contains "pineapple123", your query would be:

SELECT * from users WHERE column LIKE 'pineapple%';

And if your string always starts with any number and ends with any number like "345pineapple4565", you can use:

SELECT * from users WHERE column LIKE "%pineapple%";

Checking variable substring ( a more generic answer )

you should use '%'||?||'%' instead

for example in python we'll have something like this:

curser.execute("SELECT * FROM users WHERE column LIKE '%'||?||'%'", (variable,) )


SELECT * FROM users WHERE column LIKE '%mystring%' will do it.

LIKE means we're not doing an exact match (column = value), but doing some more fuzzy matching. "%" is a wildcard character - it matches 0 or more characters, so this is saying "all rows where the column has 0 or more chars followed by "mystring" followed by 0 or more chars".

Tags:

Sqlite