Re: [sqlite] Referencing subquery several times

2011-11-12 Thread Alexandre Courbot
Hi Igor, On Nov 12, 2011 11:45 AM, Igor Tandetnik itandet...@mvps.org wrote: This query doesn't make much sense. It appears that quite a few conditions are redundant, or else the parentheses are in the wrong places. What logic were you trying to express here? Sorry, I tried to simplify it as

Re: [sqlite] Referencing subquery several times

2011-11-12 Thread Luuk
On 12-11-2011 03:43, Igor Tandetnik wrote: On 11/11/2011 9:24 PM, Alexandre Courbot wrote: 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

Re: [sqlite] Referencing subquery several times

2011-11-12 Thread Luuk
On 12-11-2011 12:12, Alexandre Courbot wrote: Hi Igor, On Nov 12, 2011 11:45 AM, Igor Tandetnik itandet...@mvps.org wrote: This query doesn't make much sense. It appears that quite a few conditions are redundant, or else the parentheses are in the wrong places. What logic were you trying to

Re: [sqlite] Referencing subquery several times

2011-11-12 Thread Alexandre Courbot
On Sat, Nov 12, 2011 at 10:02 PM, Luuk luu...@gmail.com wrote: Should give same results as: SELECT * FROM m WHERE    c IN (SELECT * FROM a) OR    c IN (SELECT * FROM b)    AND (c IN (SELECT * FROM b)); Because of the 'OR' on the second line This can be simplified to: SELECT * FROM m

Re: [sqlite] Referencing subquery several times

2011-11-12 Thread Black, Michael (IS)
Why are you contorting yourself into just one query? Your last clause would be a complete table scan seems to me. Sounds slow versus 2 queries. Why can't you just do this? (pseudo code here) -- no table scans involved at all. select docid from b where t match 'blah'; if (rowcount 0) // the

Re: [sqlite] Referencing subquery several times

2011-11-12 Thread Darren Duncan
Alexandre Courbot 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)

Re: [sqlite] Referencing subquery several times

2011-11-12 Thread Luuk
On 12-11-2011 19:13, Darren Duncan wrote: Alexandre Courbot 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 *

Re: [sqlite] Referencing subquery several times

2011-11-12 Thread Alexandre Courbot
On Sat, Nov 12, 2011 at 11:59 PM, Black, Michael (IS) michael.bla...@ngc.com wrote: Why are you contorting yourself into just one query? It is actually part of a larger query that joins against this result. Granted, there are ways to workaround this, but I would be surprised if it was not

Re: [sqlite] Referencing subquery several times

2011-11-12 Thread Simon Slavin
On 13 Nov 2011, at 1:47am, Alexandre Courbot wrote: On Sat, Nov 12, 2011 at 11:59 PM, Black, Michael (IS) michael.bla...@ngc.com wrote: Why are you contorting yourself into just one query? It is actually part of a larger query that joins against this result. Granted, there are ways to

[sqlite] Referencing subquery several times

2011-11-11 Thread Alexandre Courbot
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 *

Re: [sqlite] Referencing subquery several times

2011-11-11 Thread Pavel Ivanov
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

Re: [sqlite] Referencing subquery several times

2011-11-11 Thread Igor Tandetnik
On 11/11/2011 9:24 PM, Alexandre Courbot wrote: 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 *