请高手指导,sql如何提高嵌套查询效率

2024-11-23 12:31:39
推荐回答(3个)
回答1:

给shop_cr 字段加索引
not改成左外连接 + 空值判断

select a.* from dh_w a,(
select c.picture_id from dh_product c left outer join (
SELECT sm_product_id FROM dh_had_upload WHERE shop_cr='IU'
union
SELECT sm_product_id FROM dh_arrange_upload WHERE shop_cr='IU'
) d on c.id = d.sm_product_id
where d.sm_product_id is null
)b where a.num =b.picture_id
ORDER BY a.id limit 0,90

回答2:

可以一部分一部分筛选吧,

回答3:

尽量少用in,使用EXISTS;另外,必要时给连接的列加上索引