sql not in ,in 优化

1.not in用left join代替

原sql:

select * from yunli_cargos where id not in(select cargoid from yunli_cargo_fee);

改为left join:

select a.* from yunli_cargos a left join yunli_cargo_fee b on b.cargoid=a.id where b.id is null

2.in 用 inner join 代替

原sql:

select * from yunli_cargos where id in(select cargoid from yunli_cargo_fee);

改为left join:

select a.* from yunli_cargos a inner join yunli_cargo_fee b on b.cargoid=a.id


你可能感兴趣的:(database)