高手求一SQL语句,高手请进!!!!!!!
表一,客户表customer
customer_id number(10) //客户ID,索引,无重复
customer_link_id number(10) //客户首选联系人
表二,客户联系人列表 customer_link
customer_link_id number(10)//客户ID,索引,无重复
customer_name varchar2(100)//客户选联系人
customer_id number(10)
假定表一数据如下,
customer_id customer_link_id
1001 2001
1002 0 //没有首选联系人
1003 2002
表二数据如下
customer_link_id customer_link_name customer_id
2001 csdn 1001
2002 www.taneipc.net 1001
2003 iloveu 1002
求一条sql语句返回以下结果:
customer_id customer_link_name
1001 csnd
1002 empty//为空
1003 www.taneipc.net
问题就出在首选联系人为空的时候
我开始是用以下select语句的:
select customer.customer_id,customer_link_name from
customer left jion customer_link on
customer.customer_link_id=customer_link.customer_link_id
结果可以返回选择
但是返回 customer_link_name 首选联系人为空处错误(变为非空值)。
每二次改为:
select customer.customer_id,customer_link_name from
customer left jion (select customer_link.customer_link_id,customer_link,customer_link_name
from customer_link inner join customer on customer.customer_link_id=customer_link.customer_link_id) on
customer.customer_link_id=customer_link_id
结果可以返回,但是出错地方依旧。
请高手指点?????????????????