文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>in和exists的SQL执行效率分析

in和exists的SQL执行效率分析

时间:2010-07-05  来源:oyanglinli

关键字: sql


  A,B两个表,

  (1)当只显示一个表的数据如A,关系条件只一个如ID时,使用IN更快:

  select * from A where id in (select id from B)

  (2)当只显示一个表的数据如A,关系条件不只一个如ID,col1时,使用IN就不方便了,可以使用EXISTS:

  select * from A

  where exists (select 1 from B where id = A.id and col1 = A.col1)

  (3)当只显示两个表的数据时,使用IN,EXISTS都不合适,要使用连接:

  select * from A left join B on id = A.id
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载