如A,B两个表,  
  当只显示一个表的数据如A,关系条件只一个如ID时,使用IN更快:  
  select   *   from   A   where   id   in   (select   id   from   B)  
   
  当只显示一个表的数据如A,关系条件不只一个如ID,col1时,使用IN就不方便了,可以使用EXISTS:  
  select   *   from   A   where   exists   (select   1   from   B   where   id   =   A.id   and   col1   =   A.col1)  
   
  当只显示两个表的数据时,使用IN,EXISTS都不合适,要使用连接:  
  select   *   from   A   left   join   B   on   id   =   A.id    

相关文章:

  • 2022-12-23
  • 2021-09-24
  • 2021-11-15
  • 2022-12-23
  • 2021-09-16
  • 2022-12-23
  • 2021-08-01
  • 2022-01-10
猜你喜欢
  • 2022-12-23
  • 2021-11-08
  • 2022-12-23
  • 2021-09-18
  • 2022-12-23
  • 2021-07-25
  • 2022-12-23
相关资源
相似解决方案