oracle使用using关键字

oracle使用using关键字sql/92标准可以使用using关键字来简化连接查询,但是只是在查询满足下面两个条件时,才能使用using关键字进行简化。1.查询必须是等值连接。2.等值连接中的列必须具有相同的名称和数据类型。例如:使用using关键字,如下:select emptno,ename,sal,deptno,dname from emp e inner join dept d using(deptno);SQL> select e.empno,e.ename,e.sal,deptno,d.dname from 2 emp e inner join dept d using(deptno); EMPNO ENAME SAL DEPTNO DNAME———- ———- ———- ———- ————– 7369 SMITH 800 20 RESEARCH 7499 ALLEN 1600 30 SALES 7521 WARD 1250 30 SALES 7566 JONES 2975 20 RESEARCH 7654 MARTIN 1250 30 SALES 7698 BLAKE 2850 30 SALES 7782 CLARK 2450 10 ACCOUNTING 7788 SCOTT 3000 20 RESEARCH 7839 KING 5000 10 ACCOUNTING 7844 TURNER 1500 30 SALES 7876 ADAMS 1100 20 RESEARCH 7900 JAMES 1800 30 SALES 7902 FORD 3000 20 RESEARCH 7934 MILLER 1300 10 ACCOUNTING 7935 XIAOXUE 5000 20 RESEARCH已选择 15 行。如上述的结果与自然连接的结果相同。使用using关键字简化连接时,需要注意以下几点:1.使用emp表和dept表中的deptno列进行连接时,,在using子句和select子句中,都不能为deptno列指定表名或表别 名。2.如果在连接查询时使用了两个表中相同的多个列,那么久可以在using子句中指定多个列名,形式如下:select… from table1 inner join table2using(column1,column2)上述的语句相当于下面的语句:select… from table1 inner join table2on table1.column1=table2.column2and table1.column2=table2.column2;如果对多个表进行检索,就必须多次使用using关键字进行指定,形式如下:select… from table1inner join table2 using(column1)inner join table3 using(column2);

上述的语句相当于下面的语句:

select… from table1,table2,table3where table1.column1=table2.column1and table2.column2=table3.table2;

都属于昨天。哪怕那山再青,那水再秀,

oracle使用using关键字

相关文章:

你感兴趣的文章:

标签云: