Can I rewrite a NOT IN query to use indexes?

Sqlite does not support the use of indexes in queries based on the NOT IN clause .

Is it possible to logically rewrite the query as follows so that it uses only the operators listed in the link above?

Request:

Select *
From table
Where table-column not in (
    Select table-column
    From table2);

Operators listed as being able to use the index:

  • column = expression
  • column> expression
  • column> = expression
  • column <Expression
  • column <= expression
  • expression = column
  • expression> column
  • expression> = column
  • expression <column
  • expression <= column
  • column IN (list of expressions)
  • column IN (subquery)
  • column NULL
+4
source share
3 answers
Select A.*
From table a
left join table2 b 
 on a.table-column = b.table-column
WHERE b.table-column is null
+2

LEFT JOIN, 6.

SQLFiddle . View Execution Plan, , , LEFT JOIN .

+4
SELECT
   *
FROM
   Table1

   LEFT JOIN Table2
   ON Table1.table-column = Table2.table_column
WHERE
   Table2.table_column IS NULL
+2
source

All Articles