提问

  • using(xx)中可以接多个列吗?
  • using(xx)中的列可以接表名或别名吗?
  • 在使用using的语句中,select * 可以使用吗?
  • 如果表有别名t,select t.* from table1 t , table2 using(xx),t.* 可以使用吗?
  • left join, right join, inner join, full outer join 可以和using一起用吗?

我们看下语法就能知道答案了。

只看答案

  • using(xx)中可以接多个列,它是一种等值连接,可以转换为 join ... on (x=y and xx=y);
  • using(xx)中的列不可以接表名或别名等限定语,默认就是指共同列,不能指定表名;
  • 在使用using的语句中,select * 可以使用,* 被扩展的顺序为using中的列,左表中的其它列,右表中的其它列
  • 如果表有别名t,select t.* from table1 t , table2 using(xx),t.* 不可以使用,using中的列不能加限定词
  • left join, right join, inner join, full outer join 可以和using一起使用,它就是简单的等值连接

inner join 就是 join, outer join有 left, right, full outer join 三种

using的使用条件是两表中列名和类型相同;

natural join更进一步,直接省掉了using,但作用和使用using相似;

inner 和 outer 的区别:内连接只返回匹配行,外连接还返回不满足条件的行;


Syntax

USING ( Simple-column-Name [ , Simple-column-Name ]* )

USING clause definition

The USING clause specifies which columns to test for equality when two tables are joined. It can be used instead of an ON clause in the JOIN operations that have an explicit join clause.

If a column in the USING clause is referenced without being qualified by a table name, the column reference points to the column in the first (left) table if the join is an INNER JOIN or a LEFT OUTER JOIN. If it is a RIGHT OUTER JOIN, unqualified references to a column in the USING clause point to the column in the second (right) table.

When a USING clause is specified, an asterisk (*) in the select list of the query will be expanded to the following list of columns (in this order):

  • All the columns in the USING clause
  • All the columns of the first (left) table that are not specified in the USING clause
  • All the columns of the second (right) table that are not specified in the USING clause

Examples


SELECT * FROM COUNTRIES JOIN CITIES
USING (COUNTRY); SELECT * FROM COUNTRIES JOIN CITIES
USING (COUNTRY, COUNTRY_ISO_CODE); SELECT * FROM oe.order_items oi JOIN oe.orders o
  USING(order_id); select t.* from hr.employees t, hr.departments d
where t.department_id = d.department_id; select * from hr.employees t inner join hr.departments d
using(department_id); select * from hr.employees t left outer join hr.departments d
using(department_id); select * from hr.employees t right outer join hr.departments d
using(department_id); select * from hr.employees t full outer join hr.departments d
using(department_id);

oracle USING 用法的更多相关文章

  1. ORACLE RETURNING 用法总结

    ORACLE RETURNING 用法总结 场景 在存储过程.PL/SQL块里需要返回INSERT.DELETE.UPDATE.MERGE等DML语句执行后的信息时使用,合理使用returning能够 ...

  2. Oracle instr用法

    1:实现indexOf功能,.从第1个字符开始,搜索第1次出现子串的位置 ,) as i from dual; select instr('oracle','or') as i from dual; ...

  3. Oracle minus用法详解及应用实例

    本文转载:https://blog.csdn.net/jhon_03/article/details/78321937 Oracle minus用法 “minus”直接翻译为中文是“减”的意思,在Or ...

  4. Oracle触发器用法实例详解

    转自:https://www.jb51.net/article/80804.htm. 本文实例讲述了Oracle触发器用法.分享给大家供大家参考,具体如下: 一.触发器简介 触发器的定义就是说某个条件 ...

  5. ORACLE SEQUENCE用法(转)

    ORACLE SEQUENCE用法 在oracle中sequence就是序号,每次取的时候它会自动增加.sequence与表没有关系. 1.Create Sequence     首先要有CREATE ...

  6. [转载]Oracle触发器用法实例详解

    本文实例讲述了Oracle触发器用法.分享给大家供大家参考,具体如下: 一.触发器简介 触发器的定义就是说某个条件成立的时候,触发器里面所定义的语句就会被自动的执行. 因此触发器不需要人为的去调用,也 ...

  7. Oracle数据库用法汇总

    一些Oracle数据库用法的小总结 1.使用insert into创建新表 insert into destdb.sub_contract (userid,contractid) select msi ...

  8. oracle sqlloader 用法

    向oracle中导入*.csv文件   1.什么是*.csv,如何得到? 里面存放的是数据表.每行代表数据库表格的一行, 每行中,每两个数据中间由逗号","分割. *.csv可以通 ...

  9. Oracle Hint 用法

    正确的语法是: select /*+ index(x idx_t) */ * from t x where x.object_id=123 /*+    */ 和注释很像,比注释多了一个“+”,这就是 ...

  10. Oracle REGEXP_INSTR 用法

    原文出处 ORACLE中的支持正则表达式的函数主要有下面四个:    1,REGEXP_LIKE :与LIKE的功能相似    2,REGEXP_INSTR :与INSTR的功能相似    3,REG ...

随机推荐

  1. Video for Linux Two API Specification

    V4L2 的使用规范,网址为:https://www.linuxtv.org/downloads/legacy/video4linux/API/V4L2_API/spec-single/v4l2.ht ...

  2. Spring Cloud Stream消费失败后的处理策略(一):自动重试

    之前写了几篇关于Spring Cloud Stream使用中的常见问题,比如: 如何处理消息重复消费 如何消费自己生产的消息 下面几天就集中来详细聊聊,当消息消费失败之后该如何处理的几种方式.不过不论 ...

  3. C# 显式转换关键字 explicit

    不同于隐式转换,显式转换运算符必须通过转换的方式来调用. 如果转换操作会导致异常或丢失信息,则应将其标记为 explicit. 这可阻止编译器静默调用可能产生意外后果的转换操作. 省略转换将导致编译时 ...

  4. 第一册:lesson ninety one.

    原文:  Poor lan. Has lan sold his house yet? Yes,he has. He sold it last week. Has he moved to his new ...

  5. 【转】ADO.Net对Oracle数据库的操作

    一 ADO.Net简介 [转自网络,收藏学习] 访问数据库的技术有许多,常见的有一下几种:开放数据库互联(ODBC). 数据访问对象(DAO).远程数据对象(RDO). ActiveX数据对象(ADO ...

  6. JQuery ajax的使用

    JQuery 真的是好东西       $.ajax({         type: "post",         url: "/DataCheck",   ...

  7. c#连接oracle数据库 DBHelper

    闲着没事自己写了一个OracleHelper类,希望大神给点建议优化 using System; using System.Collections.Generic; using System.Linq ...

  8. C- unsigned :1之位域分析

    1.首先回忆结构体 我们都知道定义一个结构体可以这样的方式定义: struct Point { float x; float y; } point; //等价于: struct Point point ...

  9. 【redis】6、redis常用命令

    [开启redis客户端,执行redis命令]    redis-cli -h 192.168.1.27 -a HoomSun1 [批量执行redis命令.把命令写到txt中,批量执行]  cat /t ...

  10. nodeJs express mongodb 建站(linux 版)

    一.环境安装 1.安装node wget http://nodejs.org/dist/v0.12.2/node-v0.12.2-linux-x64.tar.gz //下载tar xvf node-v ...