UPDATED
Finally I used this way to get filtered result.
SELECT * FROM statuses WHERE _id NOT IN (
SELECT DISTINCT statuses._id FROM statuses, filtered_sources WHERE statuses.source LIKE '%'||filtered_sources.text||'%'
UNION
SELECT DISTINCT statuses._id FROM statuses WHERE statuses.screen_name IN(SELECT filtered_users.text FROM filtered_users)
UNION
SELECT DISTINCT statuses._id FROM statuses, filtered_keywords WHERE statuses.text LIKE '%'||filtered_keywords.text||'%'
);
Why I use this way instead of combine results directly?
I’d like to use query() method rather than rawQuery() in Android.
@zapi and @sixfeetsix , thank you very much, your answers give me this idea !
Download sqlite database for test here http://db.tt/ZsEwE9TV
I have a sqlite database contains three tables : statuses, filtered_keywords, filtered_sources.
Columns in each tables:
statuses:
|_id|text|source|
filtered_keywords and filtered_sources:
|_id|text|
now I’d like to filter query results from statuses contains words in filtered_keywords and filtered_sources.
I know I can use LIKE in sqlite, but I can’t use it like IN function.
SELECT * FROM statuses WHERE text in (SELECT text FROM filtered_sources);
So I have to query all data in filtered_sources and filtered_keywords as Cursor first, then build a long where clause, it’s really slow.
Is there any simple way to get the filtered result ?
You can do something like this:
For example:
outputs:
UPDATE:
I updated the
SELECTstatement as the OP points out that the previous version didn’t work when one of the two filtered_* tables is empty.