在oracle连接(join)中使用using关键字
34. View the Exhibit and examine the structure of the ORDERS and ORDER_ITEMS tables.
Evaluate the following SQL statement:
SELECT oi.order_id, product_id, order_date
FROM order_items oi JOIN orders o
USING(order_id);
Which statement is true regarding the execution of this SQL statement?
A. The statement would not execute because table aliases are not allowed in the JOIN clause.
B. The statement would not execute because the table alias prefix is not used in the USING clause.
C. The statement would not execute because all the columns in the SELECT clause are not prefixedwith table aliases.
D. The statement would not execute because the column part of the USING clause cannot have a qualifier in the SELECT list.
Answer: D
分析上面这道题,要理解using关键字的用法:
在oralce中使用natural join,也就是自然连接。
使用natraul join进行连接查询,并且两张表中如果有多个字段是具有相同的名称和数据类型的,那么这些字段都将被oracle自作主张的将他们连接起来。但实际上我们有时候是不需要这样来连接的。我们只需要将他们的多个具有相同的名称和数据类型的字段中挑选一两个。这时候我们就需要用到using 关键字了。在Oracle中的join连接中使用using关键字,是相对于natural join的。