Reputation: 593
I have db with scheme 1. _id 2. word
And i have ArrayList with for example 5 words (a1, a2, a3, a4, a5)
What is the best way to construct query to get words from DB which don't contain words from ArrayList?
Sowthing like
Select * from MYTABLE where WORD not in "all words from ArrayList"
Upvotes: 1
Views: 1448
Reputation: 3836
Pseudo Query
Select * from mytable
Use the except operator against a selection containing words in array list http://en.wikipedia.org/wiki/Set_operations_(SQL)#EXCEPT_operator
Upvotes: 0
Reputation: 81349
Build a string representing the set of words, and use that as an argument to the query.
StringBuilder wordSet = new StringBuilder();
wordSet.append('(');
for( String word : wordsList )
{
if(wordSet.length() > 1)
wordSet.append(',');
wordSet.append(word);
}
wordSet.append(')');
Upvotes: 3