Spirrow
Spirrow

Reputation: 1150

SQLite multiple where in the same column

I have a table like this:

Char1       Char2       Difficulty
--------------------------------------------------
jon          sara          1
pablo        victor        2
laura        patricia      1
marta        juanjo        3
marina       goku          4

I want to select all the rows where difficulty = 1 and difficulty = 2. I have tried to do:

"SELECT * FROM " + table + " WHERE " + DatabaseOpenHelper.COLUMN_DIFFICULTY + " LIKE '1%'" + " AND " + DatabaseOpenHelper.COLUMN_DIFFICULTY + " LIKE '2%'" 

But it's not working, I am new to SQLite so I will appreciate any explanation with the answer. Thanks!

Upvotes: 1

Views: 272

Answers (1)

laalto
laalto

Reputation: 152797

There are multiple problems:

  1. You did not actually describe your problem beyond "it's not working".

  2. You'd need whitespace between column names and the LIKE keyword.

  3. You don't need LIKE at all. Use =1 in place of LIKE '1%' etc.

  4. To combine multiple conditionals, you probably want OR in place of AND. A single row column cannot be 1 and 2 at the same time.

Upvotes: 1

Related Questions