Sqlite does not support the use of indexes in queries based around a NOT IN clause
是否可以逻辑重写如下所示的查询,使其只使用上面链接中列出的运算符?
查询:
Select *
From table
Where table-column not in (
Select table-column
From table2);
列出的运营商可以使用索引:
答案 0 :(得分:4)
使用LEFT JOIN as described in section 6。
带有示例数据here的SQLFiddle。展开查看执行计划以确认原始查询执行表扫描,而LEFT JOIN查询使用索引。
答案 1 :(得分:2)
SELECT
*
FROM
Table1
LEFT JOIN Table2
ON Table1.table-column = Table2.table_column
WHERE
Table2.table_column IS NULL
答案 2 :(得分:2)
Select A.*
From table a
left join table2 b
on a.table-column = b.table-column
WHERE b.table-column is null