oracle 自联接

127. Examine the data in the CUSTOMERStable:

CUSTNO  CUSTNAME  CITY

1    KING    SEATTLE

2    GREEN   BOSTON

3    KOCHAR   SEATTLE

4    SMITH   NEW YORK

You want to list all cities that havemore than one customer along with the customer details.

Evaluate the following query:

SQL>SELECT c1.custname, c1.city

FROM Customers c1 __________________Customers c2

ON (c1.city=c2.city ANDc1.custname<>c2.custname);

Which two JOIN options can be used inthe blank in the above query to give the correct output? (Choose

two.)

A. JOIN                

B. NATURAL JOIN

C. LEFT OUTER JOIN

D. FULL OUTER JOIN

E. RIGHT OUTER JOIN 


SQL> select c1.custname,c1.city from Customers c1
  2  join
  3  Customers c2
  4  on (c1.city=c2.city and c1.custname<>c2.custname);

CUSTNAME   CITY
---------- ----------
KOCHAR     SEATTLE
KING       SEATTLE

SQL> select c1.custname,c1.city from Customers c1
  2  left outer join
  3    Customers c2 on (c1.city=c2.city and c1.custname<>c2.custname);

CUSTNAME   CITY
---------- ----------
KOCHAR     SEATTLE
KING       SEATTLE
GREEN      BOSTON
SMITH      NEW YORL

SQL> select c1.custname,c1.city from Customers c1
  2  right outer join 
  3    Customers c2 on (c1.city=c2.city and c1.custname<>c2.custname);

CUSTNAME   CITY
---------- ----------
KING       SEATTLE
KOCHAR     SEATTLE

SQL> select c1.custname,c1.city from Customers c1
  2  full outer join
  3   Customers c2 on (c1.city=c2.city and c1.custname<>c2.custname);

CUSTNAME   CITY
---------- ----------
KOCHAR     SEATTLE
KING       SEATTLE
GREEN      BOSTON
SMITH      NEW YORL

SQL> select c1.custname,c1.city from Customers c1
  2  natural join 
  3  Customers c2 on (c1.city=c2.city and c1.custname<>c2.custname);
Customers c2 on (c1.city=c2.city and c1.custname<>c2.custname)
             *
ERROR at line 3:
ORA-00933: SQL command not properly ended

Customers c2 on (c1.city=c2.city and c1.custname<>c2.custname);


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值