In a development environment with SQLite 3.7.11
and Java
, despite having read the following answers:
am finding the usage of the SQLite IN
clause not very straight-forward.
Assume a simple table TEST
with the following structure:
----------------------------
id PRODUCT TAG
(int) (text) (text)
----------------------------
1 Cinthol Soap, Bath, Cleaning
2 Vim Dishwash, Kitchen, Cleaning
3 Burger Food, Breakfast, Lunch, Dinner
The following queries are behaving this way:
----------------------------------------------------------------------------
Query Result Expected
----------------------------------------------------------------------------
SELECT PRODUCT FROM TEST WHERE TAG IN('Soap') Cinthol Cinthol
SELECT PRODUCT FROM TEST WHERE TAG IN('Dinner') <EMPTY> Burger
SELECT PRODUCT FROM TEST WHERE TAG IN('Soap', 'Bath') <EMPTY> Cinthol
SELECT PRODUCT FROM TEST WHERE TAG IN('Cleaning') <EMPTY> Cinthol, Vim
So the questions are:
- Except the first query, why are the others not producing the expected results? Is there something fundamentally wrong in the understanding?
- If wrong, what is the right query to get the expected results (without using the
instr
function)?
Furthermore, the TAG
column eventually has to be bound with an array of tokens in Java, building the query dynamically. The answers listed above have pointers to that, though.
Thanks in advance!