对两个表的简单外连接
下列查询使用与前面示例相同的 Projection 子句、表和比较条件,但这一次它用 GBase
8s 扩展语法创建简单外连接。
图: 查询
SELECT c.customer_num, c.lname, c.company,
c.phone, u.call_dtime, u.call_descr
FROM customer c, OUTER cust_calls u
WHERE c.customer_num = u.customer_num;
cust_calls 表前面的附加关键字 OUTER 使该表成为从属表。外连接导致查询返回有关所有
客户的信,而不管它们是否已致电客户服务中心。检索控制表 customer 的所有行,并且将
NULL 值指定给从属表 cust_calls 的列,如下所示。
图: 查询结果
customer_num 101
lname Pauli
company All Sports Supplies
phone 408-789-8075
call_dtime
call_descr
customer_num 102
lname Sadler
company Sports Spot
phone 415-822-1289
call_dtime
call_descr
⋮
customer_num 107
lname Ream
company Athletic Supplies
phone 415-356-9876
call_dtime
call_descr
customer_num 108
lname Quinn
company Quinn's Sports
phone 415-544-8729
call_dtime
call_descr