数据库
首页 > 数据库> > sql优化-使用exists代替distinct

sql优化-使用exists代替distinct

作者:互联网

and c_ajbh in (select distinct c_ajbh from db_zxzhld.t_zhld_zbajxx where n_dbzt = 1 and c_zblx = '1003' and c_gy = '2550' )
改写为:
and exists (select c_ajbh from db_zxzhld.t_zhld_zbajxx where n_dbzt = 1 and c_zblx = '1003' and c_gy = '2550' )

一旦满足条件则立刻返回。所以使用exists的时候子查询可以直接去掉distinct。从执行计划来看使用exists可以消除分组,提高效率。

标签:exists,ajbh,distinct,gy,sql,zhld,select
来源: https://www.cnblogs.com/zhangfx01/p/14872393.html