自然连接 natural join

探讨了SQL中自然连接(NATURAL JOIN)的正确使用方法,并通过具体例子说明了WHERE子句的位置对于查询结果的影响。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

74. View the Exhibit and examine the structure of the ORDER_ITEMS and ORDERS 
tables. 
You are asked to retrieve the ORDER_ID, PRODUCT_ID, and total price 
(UNIT_PRICE multiplied by QUANTITY), where the total price is greater than 
50,000. 
You executed the following SQL statement: 
SELECT order_id, product_id, unit_price*quantity "Total Price" 
FROM order_items 
WHERE unit_price*quantity > 50000 NATURAL JOIN orders;

Which statement is true regarding the execution of the statement? 


A. The statement would execute and provide the desired result. 
B. The statement would not execute because the ON keyword is missing in the 
NATURAL JOIN clause. 
C. The statement would not execute because the WHERE clause is before the 
NATURAL JOIN clause. 
D. The statement would not execute because the USING keyword ismissing in 
the NATURAL JOIN 
clause. 
Answer: C 



自然连接(NATURAL JOIN)是一种特殊的等价连接,它将表中具有相同名称的列
自动进行记录匹配。自然连接不必指定任何同等连接条件。 


下面举例论证:

SQL> select deptno from scott.dept;

    DEPTNO
----------
        10
        20
        30
        40

SQL> select deptno from scott.emp;

    DEPTNO
----------
        20
        30
        30
        20
        30
        30
        10
        20
        10
        30
        20

    DEPTNO
----------
        30
        20
        10

14 rows selected.



SQL> select deptno,ename from scott.dept natural join scott.emp where deptno>30; 

no rows selected <span style="color:#ff0000;">//先对两个表做自然连接,对连接结果在做deptno>30的条件输出</span>


SQL> select deptno,ename from scott.dept  where deptno>30 natural join scott.emp;
select deptno,ename from scott.dept  where deptno>30 natural join scott.emp
                                                     *
ERROR at line 1:
ORA-00933: SQL command not properly ended





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

huangliang0703

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值