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)
这两条语句是什么意思,能给详细的说明吗?
...全文
987打赏收藏
请教sql语句的意思
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) 这两条语句是什么意思,能给详细的说明吗?
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条SQL中的EXISTS默认有过滤重复记录功能。我觉得这是比较这2条SQL最本质的区别。[Quote=引用楼主 chongxiaoyihe 的帖子:]
SQL code
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)