> I know this could be done more easily, but I have to keep this
> structure (i.e. cannot JOIN for instance). My question is, how could I
> avoid repeating the subqueries after the AND NOT, since they will
> return the same set as the previous ones?

With your restriction on query structure you cannot do that.

> In case I do not replace
> them, would SQLite be able to optimize and only run them once?

No, SQLite doesn't have this sort of optimization AFAIK.


Pavel


On Fri, Nov 11, 2011 at 9:24 PM, Alexandre Courbot <gnu...@gmail.com> wrote:
> Hi everybody,
>
> Here is a simplified version of the statement I try to run (let a, b,
> and m be tables with only one column named c containing integers):
>
> SELECT * FROM m WHERE
>    c IN (SELECT * FROM a) OR
>    c IN (SELECT * FROM b)
>    AND (NOT c IN (SELECT * FROM a)
>         OR  c IN (SELECT * FROM b));
>
> I know this could be done more easily, but I have to keep this
> structure (i.e. cannot JOIN for instance). My question is, how could I
> avoid repeating the subqueries after the AND NOT, since they will
> return the same set as the previous ones? In case I do not replace
> them, would SQLite be able to optimize and only run them once?
>
> Thanks,
> Alex.
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to