Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite Select from where column contains string?

Tags:

sqlite

What I currently have selects based on a column having the same value..

"SELECT * FROM users WHERE uuid = ?"

But what if I want to return a row based on one of the columns "containing" a string value? Some pseudo code would be:

SELECT * FROM users
WHERE column CONTAINS mystring

Any help is appreciated, I have been searching for other answers but to no avail.

like image 864
ThatGuy343 Avatar asked Jan 21 '15 05:01

ThatGuy343


2 Answers

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".

like image 169
John3136 Avatar answered Oct 20 '22 21:10

John3136


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%";
like image 20
Semicolon Avatar answered Oct 20 '22 22:10

Semicolon