Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite query to match text string in column

Tags:

sql

sqlite

I have a database column that contains text in CSV format. A sample cell looks like this:

Audi,Ford,Chevy,BMW,Toyota

I'd like to generate a query that matches any column with the string 'BMW'. How can I do this in SQL?

like image 472
turtle Avatar asked Apr 16 '13 09:04

turtle


People also ask

Can I use varchar in SQLite?

You can declare a VARCHAR(10) and SQLite will be happy to store a 500-million character string there. And it will keep all 500-million characters intact. Your content is never truncated. SQLite understands the column type of "VARCHAR(N)" to be the same as "TEXT", regardless of the value of N.

What is difference between text and varchar in SQLite?

Some Differences Between VARCHAR and TEXT The VAR in VARCHAR means that you can set the max size to anything between 1 and 65,535. TEXT fields have a fixed max size of 65,535 characters. A VARCHAR can be part of an index whereas a TEXT field requires you to specify a prefix length, which can be part of an index.

What is wildcard in SQLite?

SQLite provides two wildcards for constructing patterns. They are percent sign % and underscore _ : The percent sign % wildcard matches any sequence of zero or more characters. The underscore _ wildcard matches any single character.


2 Answers

You can use wildcard characters: %

select * from table 
where name like '%BMW%'
like image 200
Vishal Suthar Avatar answered Oct 16 '22 16:10

Vishal Suthar


I think you are looking for something like

SELECT * FROM Table
WHERE Column LIKE '%BMW%'

the % are wildcards for the LIKE statement.

More information can be found HERE

like image 45
Xavjer Avatar answered Oct 16 '22 15:10

Xavjer