inZania <z...@claes.biz> wrote: > The situation is this: there is a table, "cards", which I am > searching. Each card has a card_id, name, text, etc. There is also a > table "card_tags" which has only the rows "card_id" and "tag", > because a single card may have several tags. The query I'm trying to > execute is attempting to search the card's name, text, OR any of its > tags for a specific search string. > > Here's the query I've constructed that is operating slowly: > SELECT DISTINCT cards.* FROM cards LEFT JOIN card_tags ON > cards.card_id=card_tags.card_id WHERE (cards.name LIKE '%query%' OR > cards.text LIKE '%query%' OR card_tags.tag LIKE '%query%')
Try this: select * from cards where card_id in ( select card_id from cards where name LIKE '%query%' OR text LIKE '%query%' union all select card_id from card_tags where tag LIKE '%query%' ); Igor Tandetnik _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users