c oracle 联合查询语句,三表关联查询,如何构造select语句保证oracle优先关联表A与表B而不是优先关联A与C?...

SQL> edit

已写入文件 afiedt.buf

1  select a.ename, b.dname, c.job

2  from emp a,dept b,bonus c

3* where a.deptno=b.deptno and a.job=c.job

SQL> set autotrace on;

SQL> /

未选定行

Execution Plan

----------------------------------------------------------

0      SELECT STATEMENT Optimizer=CHOOSE

1    0   NESTED LOOPS

2    1     MERGE JOIN

3    2       SORT (JOIN)

4    3         TABLE ACCESS (FULL) OF 'BONUS'

5    2       SORT (JOIN)

6    5         TABLE ACCESS (FULL) OF 'EMP'

7    1     TABLE ACCESS (BY INDEX ROWID) OF 'DEPT'

8    7       INDEX (UNIQUE SCAN) OF 'PK_DEPT' (UNIQUE)

Statistics

----------------------------------------------------------

106  recursive calls

0  db block gets

31  consistent gets

1  physical reads

0  redo size

322  bytes sent via SQL*Net to client

372  bytes received via SQL*Net from client

1  SQL*Net roundtrips to/from client

1  sorts (memory)

0  sorts (disk)

0  rows processed

SQL> edit

已写入文件 afiedt.buf

1  select /*+ordered*/a.ename, b.dname, c.job

2  from emp a,dept b,bonus c

3* where a.deptno=b.deptno and a.job=c.job

SQL> /

未选定行

Execution Plan

----------------------------------------------------------

0      SELECT STATEMENT Optimizer=CHOOSE (Cost=8 Card=82 Bytes=4428

)

1    0   HASH JOIN (Cost=8 Card=82 Bytes=4428)

2    1     HASH JOIN (Cost=5 Card=82 Bytes=3936)

3    2       TABLE ACCESS (FULL) OF 'EMP' (Cost=2 Card=82 Bytes=213

2)

4    2       TABLE ACCESS (FULL) OF 'DEPT' (Cost=2 Card=82 Bytes=18

04)

5    1     TABLE ACCESS (FULL) OF 'BONUS' (Cost=2 Card=82 Bytes=492

)

Statistics

----------------------------------------------------------

122  recursive calls

0  db block gets

22  consistent gets

3  physical reads

0  redo size

322  bytes sent via SQL*Net to client

372  bytes received via SQL*Net from client

1  SQL*Net roundtrips to/from client

0  sorts (memory)

0  sorts (disk)

0  rows processed

具体访问表的顺序 看的稀里糊涂 先后的顺序应该是  第一种情况(8-7-6-5-4-3-2-1-0)  dept-emp-bonus  第二种情况 (5-4-3-2-1-0) bonus-dept-emp

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值