Tony
Tony

Reputation: 3805

SQLite exception in LIKE query

I've got search query "aa bb" and also there is "aa bb cc" row in table. So my sql query should return that row. This is how I do:

select * from company
   where 
      (ASCII_NAME like %'aa'% 
      and ASCII_NAME like %'bb'%) 
   and CITY_ID=0 and parent=-1;

But my log says:

android.database.sqlite.SQLiteException: near "%": syntax error (code 1): , while compiling: select * from company where (ASCII_NAME like %'aa'% and ASCII_NAME like %'bb'%) and CITY_ID=0 and parent=-1

What is wrong?

Upvotes: 0

Views: 137

Answers (2)

Suman Dey
Suman Dey

Reputation: 66

Include % sign in single quotes. Like:

select emp_name from employee where emp_name like '%s%';

Upvotes: 1

Murtaza Khursheed Hussain
Murtaza Khursheed Hussain

Reputation: 15336

Your syntax is wrong

select * from company
   where 
      (ASCII_NAME like '%aa%' 
      and ASCII_NAME like '%bb%') 
   and CITY_ID=0 and parent=-1;

Upvotes: 1

Related Questions