tb.oprorder
from tb
inner join rb1
using (stfaprid)
where tb1.jugsumid = #jugsumid#
and tb1.blnorg = #blnorg#
and isvld = '1'
order by tb.typ asc, tb.oprorder asc
`sql/92`标准可以使用`using`关键字来简化连接查询,但是只是在查询满足下面两个条件时,才能使用`using`关键字进行简化。
>
> 1. 查询必须是等值连接。
> 2. 等值连接中的列必须具有相同的名称和数据类型。
>
>
>
例如:使用`using`关键字,如下:
select emptno,ename,sal,deptno,dname from emp e inner join dept d using(deptno);
如上述语句执行的结果与自然连接的结果相同。
使用`using`关键字简化连接时,需要注意以下几点:
>
> 1. 使用emp表和dept表中的deptno列进行连接时,在`using`子句和`select`子句中,都不能为deptno列指定表名或表别名。
> 2. 如果在连接查询时使用了两个表中相同的多个列,那么就可以在`using`子句中指定多个列名。
>
>
>
形式如下:
select… from table1 inner join table2 using(column1,column2)
上述的语句相当于下面的语句:
select… from table1 inner join table2
on table1.column1=table2.column2
and table1.column2=table2.column2;
如果对多个表进行检索,就必须多次使用`using`关键字进行指定,形式如下:
select… from table1
inner join table2 using(column1)
inner join table3 using(column2);
上述的语句相当于下面的语句:
select… from table1,table2,table3
where table1.column1=table2.column1
and table2.column2=table3.column2;
### 二、再议using
在`Oracle`中的`join`连接中使用`using`关键字,相对于`natural join`。
在前面提到,如果是使用`natraul join`,并且两张表中如果有多个字段是具有相同的名称和数据类型,那么这些字段都将被`oracle`自作主张的将他们连接起来。
但实际上我们有时候是不需要这样来连接的。我们只需要将他们的多个具有相同的名称和数据类型的字段中挑选一两个。这时候我们就需要用到`using` 关键字了。
下面是一个例子。
有一个表是sales,还有一个表是costs,这两个表中都有两个字段分别是pro\_id和time\_id。我们暂且不去考虑下面连接的实际意义,仅作语法上的研究。
如果使用natural连接,默认情况下,两个字段将会被自然地连接在一起。
Select * from Sales natural join costs;
和
Select * from Sales join costs on Sales.prod_id = costs.prod_id and sales.time_id = costs.time_id
和
Select * from Sales ,costs Where Sales.pro_id = cost.prod_id
and sales.time_id = costs.time_id
得到的结果应该是一样的。
### 最后
如果你已经下定决心要转行做编程行业,在最开始的时候就要对自己的学习有一个基本的规划,还要对这个行业的技术需求有一个基本的了解。有一个已就业为目的的学习目标,然后为之努力,坚持到底。如果你有幸看到这篇文章,希望对你有所帮助,祝你转行成功。
![](https://img-blog.csdnimg.cn/img_convert/54a6b04f29167333b139d2753f60db9f.png)