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 (SELECT * FROM b)
>> AND (NOT c IN (SELECT * FROM a)
>> OR c IN (SELECT * FROM b));
>
> 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?
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));
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 WHERE
c IN (SELECT * FROM a) OR
c IN (SELECT * FROM b);
Maybe this would be more efficient?
SELECT * FROM m WHERE
c IN (SELECT * FROM a
UNION
SELECT * FROM b);
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users