官方inner joins及using用法解释如下:
例:表table1有id,name字段,表table2有id,age字段,通过id字段关联table1和table2,查询所有人员的性名和年龄
若是select * from table1,table2 where table1.id=table2.id,则因id在二表中都存在,会重复显示,若想
二表连查且相同列只显示一列,则用下面的方式
select * from table1 inner join table2 using(id)。
附代码如下:
SQL> create table table1(id number(3),name varchar2(20));
表已创建。
SQL> create table table2(id number(3),age number(3));
表已创建。
SQL> insert into table1 values(1,'xx');
已创建 1 行。
SQL> insert into table1 values(2,'yy');
已创建 1 行。
SQL> insert into table2 values(1,20);
已创建 1 行。
SQL> commit;
提交完成。
SQL> select * from table1 t1,table2 t2 where t1.id=t2.id;
ID NAME ID AGE
---------- -------------------- ---------- ----------
1 xx 1 20
SQL> select * from table1 t1 inner join table2 using(id);
ID NAME AGE
---------- -------------------- ----------
1 xx 20
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/21251711/viewspace-1102674/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/21251711/viewspace-1102674/