Lui*_*ins 1 sql firebird select notin
select mid from aplicacao\nwhere mid not in\n(\nselect distinct mid from aplicacao\ninner join prod_app on prod_app.mid=aplicacao.mid\nwhere prod_app.coditem=1\n)\nRun Code Online (Sandbox Code Playgroud)\n\n我尝试在 firebird 上搜索解决方案来改进此查询,但不幸的是 \xc2\xb4t 没有成功。请问有人可以帮助我吗?
\nThe most common solution for IN (and NOT IN) performance problems is to use EXISTS (or NOT EXISTS) instead:
select mid from aplicacao
where not exists (
select 1 from prod_app
where prod_app.mid = aplicacao.mid and prod_app.coditem=1
)
Run Code Online (Sandbox Code Playgroud)
Another solution is to use a LEFT JOIN and filter on non-existence of the right side:
select mid from aplicacao
left join prod_app
on prod_app.mid = aplicacao.mid and prod_app.coditem=1
where prod.app.coditem is null
Run Code Online (Sandbox Code Playgroud)
Note that additional filter conditions on prod_app (like prod_app.coditem=1) need to be part of the join condition, not of the where clause.