SQL 查询优化(NOT IN 子句)多表
SQL Query Optimization (NOT IN Clause) Multible tables
大家好!
有没有办法优化此 SQL 查询,使其更快?例如:
伪:
[...] 不在 (table1, table2, table3, ...)
有问题的查询:
SELECT data FROM _ WHERE p_=:e
AND status <= 1
AND s_ >= :f
AND c_ IS NULL
AND _.id NOT IN (SELECT id FROM c_)
AND _.id NOT IN (SELECT id FROM p_)
AND _.id NOT IN (SELECT id FROM e_)
AND _.id NOT IN (SELECT id FROM f_)
AND _.id NOT IN (SELECT id FROM w_)
AND _.id NOT IN (SELECT id FROM a_)
AND _.id NOT IN (SELECT id FROM k_)
AND _.id NOT IN (SELECT id FROM w_)
AND _.id NOT IN (SELECT id FROM r_) ORDER BY s_ DESC
不存在可能会有帮助,例如
AND _.id NOT exists (SELECT 1 FROM c_ where c_.id = _.id )
大家好!
有没有办法优化此 SQL 查询,使其更快?例如:
伪:
[...] 不在 (table1, table2, table3, ...)
有问题的查询:
SELECT data FROM _ WHERE p_=:e
AND status <= 1
AND s_ >= :f
AND c_ IS NULL
AND _.id NOT IN (SELECT id FROM c_)
AND _.id NOT IN (SELECT id FROM p_)
AND _.id NOT IN (SELECT id FROM e_)
AND _.id NOT IN (SELECT id FROM f_)
AND _.id NOT IN (SELECT id FROM w_)
AND _.id NOT IN (SELECT id FROM a_)
AND _.id NOT IN (SELECT id FROM k_)
AND _.id NOT IN (SELECT id FROM w_)
AND _.id NOT IN (SELECT id FROM r_) ORDER BY s_ DESC
不存在可能会有帮助,例如
AND _.id NOT exists (SELECT 1 FROM c_ where c_.id = _.id )