在执行带有USING关键字的JOIN时

在执行带有USING关键字的JOIN时

本文介绍了在执行带有USING关键字的JOIN时,选择列表中不能包含限定词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在看一个没有关于正确答案的解释的实践测试.我很困惑的问题基本上是问以下SQL语句为什么永远无法工作:

I am looking at a practice test that doesn't have explanations about the correct answers. The question I'm confused about basically asks why the following SQL statement can never work:

SELECT oi.order_id, product_jd, order_date
FROM order_items oi JOIN orders o
USING(order_id);

给出的答案是:由于USING子句的列部分在SELECT列表中不能包含限定符,因此该语句将不会执行"

The answer it gave was: "The statement would not execute because the column part of the USING clause cannot have a qualifier in the SELECT list"

有人可以详细说明吗?我很沮丧.

Can someone elaborate on this? I am pretty stumped.

推荐答案

它在抱怨oi限定词:

SELECT oi.order_id, product_jd, order_date
       ^^^

Oracle不允许将限定符与using联接一起使用.最明确的解决方法是使用常规联接:

Oracle does not allow qualifiers in combination with a using join. The clearest way out is using a regular join:

SELECT oi.order_id, product_jd, order_date
FROM order_items oi
JOIN orders o ON o.order_id = oi.order_id

您也可以省略限定符. using语句告诉Oracle,即使有两个称为order_id的字段,它们都相等:

You can also omit the qualifier. The using statement tells Oracle that even though there are two fields called order_id, they are both equal:

SELECT order_id, product_jd, order_date
FROM order_items oi JOIN orders o
USING(order_id)

这篇关于在执行带有USING关键字的JOIN时,选择列表中不能包含限定词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 22:18