select tb2.* from tb1,tb2  where tb2.t5=tb1.t3 and tb1.t7=tb2.t9 and tb1.t10 = tb2.t13
select *  from tb2 where exists( select 1 from tb1 where tb2.t5=tb1.t3 and tb1.t7=tb2.t9 and tb1.t10 = tb2.t13)
这两条语句是什么意思,能给详细的说明吗?

解决方案 »

  1.   

    select tb2.* from tb1,tb2  where tb2.t5=tb1.t3 and tb1.t7=tb2.t9 and tb1.t10 = tb2.t13从tb1,tb2里面检索数据,检索的是满足 tb2.t5=tb1.t3 和 tb1.t7=tb2.t9 和 tb1.t10 = tb2.t13 这几个条件的 tb2 里面的所有数据
    其中 t5 t3  t7 t9 t10  t13  都是tb2 或者 tb1的字段  ‘.’ 前面是谁就是谁的select *  from tb2 where exists( select 1 from tb1 where tb2.t5=tb1.t3 and tb1.t7=tb2.t9 and tb1.t10 = tb2.t13)
    这句主题是从一个查询结果集里找数据,检索tb2里面所有 存在于 select 1 from tb1 where tb2.t5=tb1.t3 and tb1.t7=tb2.t9 and tb1.t10 = tb2.t13 这个结果集里面的数据。
    select 1 from tb1 where tb2.t5=tb1.t3 and tb1.t7=tb2.t9 and tb1.t10 = tb2.t13 
    这个里面  select 1 和 select * 是一个意思 。同第一条sql
      

  2.   

    第2条SQL中的EXISTS默认有过滤重复记录功能。我觉得这是比较这2条SQL最本质的区别。