Smith
Smith

Reputation: 5961

sqlite search multiple column

am trying to perform a case sensitive serach of all columns in a table, so i did somthing like this

Select * From mytable Where col1 || '--' || col2 || '--' || etc like '%SomeValue%'

but it alwas return the same result for both upper case and lower case. if i do this

Select * From mytable Where col1 like '%SomeValue%' OR col1 like '%SomeValue%' etc

i get the desired result. The problems here is that i cannot use this second query as i have about 36 columns to search, and writing col1 like '%SomeValue%' up to 36 times would be unecessary.

does anyone have any solution?

Upvotes: 2

Views: 6903

Answers (1)

Doug Currie
Doug Currie

Reputation: 41170

One solution is to use glob instead of like

sqlite> select * from sqlite_master where ('foo' || '--' || 'bar') like '%Bar%';
table|t|t|2|CREATE TABLE t (a)
sqlite> select * from sqlite_master where ('foo' || '--' || 'bar') glob '*Bar*';
sqlite> select * from sqlite_master where ('foo' || '--' || 'bar') glob '*bar*';
table|t|t|2|CREATE TABLE t (a)
sqlite> 

Another solution is to use pragma case_sensitive_like

sqlite> PRAGMA case_sensitive_like = 1;
sqlite> select * from sqlite_master where ('foo' || '--' || 'bar') like '%Bar%';
sqlite> select * from sqlite_master where ('foo' || '--' || 'bar') like '%bar%';
table|t|t|2|CREATE TABLE t (a)
sqlite> 

Upvotes: 2

Related Questions