请教sql语句的意思

chongxiaoyihe 2008-12-31 10:14:21

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)


这两条语句是什么意思,能给详细的说明吗?
...全文
98 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
chongxiaoyihe 2008-12-31
  • 打赏
  • 举报
回复
这两条语句的区别是什么啊?
ruihuahan 2008-12-31
  • 打赏
  • 举报
回复
join 语义的多种表达。
风天逸 2008-12-31
  • 打赏
  • 举报
回复
楼上正解
Divina 2008-12-31
  • 打赏
  • 举报
回复
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
mantisXF 2008-12-31
  • 打赏
  • 举报
回复
第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)




这两条语句是什么意思,能给详细的说明吗?
[/Quote]
chongxiaoyihe 2008-12-31
  • 打赏
  • 举报
回复
我执行的结果不一样啊,前面的条数多,后面查询的条数少
denghuozhi 2008-12-31
  • 打赏
  • 举报
回复
结果一样,写法不同而已。
执行的效率也有所不同

17,378

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧