sql:exists 与 not exists

$sql = "select a.Vchcode,a.vdate,a.btypeid,a.vcomment,a.total,a.vnumber,b.bfullname,b.artotal,b.area from ldtdlyndx a left join ldtbtype b on a.btypeid = b.btypeid where not exists(select b.vchcode from lddlyndx_ex b where b.vchcode=a.Vchcode) ";

  

 表a与表b之间的数据存在关系,a表数据1到4与b表数据1-1到4-1有一一对应关系,使用exists可取出a表的【数据1、数据2、数据3、数据4】,而not exists 可以取出【数据5】,虽然not in也可以实现该功能,但是效率却比exists差远了,做个记录

听说还有个功能叫去重,有空研究一下;

原文地址:https://www.cnblogs.com/dayin1/p/11857357.html