提问

  • 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. Spring Cloud Config采用Git存储时两种常用的配置策略

    由于Spring Cloud Config默认采用了Git存储,相信很多团队在使用Spring Cloud的配置中心时也会采用这样的策略.即便大家都使用了Git存储,可能还有各种不同的配置方式,本文就 ...

  2. C# Task用法

    1.Task的优势 ThreadPool相比Thread来说具备了很多优势,但是ThreadPool却又存在一些使用上的不方便.比如: ◆ ThreadPool不支持线程的取消.完成.失败通知等交互性 ...

  3. WPF 绕圈进度条(二)

    一 以前的方案 以前写过一个圆点绕圈的进度条,根据参数圆点个数和参数每次旋转角度,主要是在cs文件中动态添加圆点,通过后台定时器,动态设置角度后用正弦余弦计算(x,y)的位置. 此方案优点:动态添加L ...

  4. 禅道导入bugfree 3.0的数据

    禅道项目导入bugfree功能只支持到2.0, 官方不提供3.0的导入,只好自己写了一个.因为bugfree 3.0换人开发了,表结构和禅道差别很大,所以,这个工具不是完全转换,一些History表内 ...

  5. [nodejs] nodejs开发个人博客(七)后台登陆

    定义后台路径 访问这个路径进入后台页面 http://localhost:8888/admin/login 在后台路由控制器里面(/admin/index.js)调用登陆控制器(/admin/logi ...

  6. 【Java每日一题】20170307

    20170306问题解析请点击今日问题下方的“[Java每日一题]20170307”查看(问题解析在公众号首发,公众号ID:weknow619) package Mar2017; public cla ...

  7. 详解Parcel:快速,零配置web应用打包工具。

    译者按: 新一代Web应用打包工具Parcel横空出世,快速.零配置的特点让人眼前一亮. 原文: Everything You Need To Know About Parcel: The Blazi ...

  8. js 实现 0-9 随机排序

    function randomsort(a, b) {return Math.random()>0.5 ? -1 : 1;//用Math.random()函数生成0~1之间的随机数与0.5比较, ...

  9. bootstrap table 获取数据后的前台页面(后台怎么传就不必详细说明了吧)

    <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ t ...

  10. 什么是CSR以及CSR的作用和生成

    什么是CSR以及CSR的作用和生成 来源:https://www.trustasia.com/news-201801-what-is-the-role-and-generation-of-csr-an ...