日期:2014-05-18  浏览次数:20480 次

新手初学多表查询问题
现在有两个表 

common 公用表 表中字段 ndeptcode(这个字段与cust表中的custcode字段对应,)

cust 客户表 custname,custaddr,custcode 

我想要得出common表中的ndeptcode对应的custname

应该怎样写? 我是这样写的,对吗? select custname from cust where custcode in (select ndeptcode from common)

谢谢

------解决方案--------------------
select b.custname from common a join cust b on a.ndeptcode=b.custcode
------解决方案--------------------
那样写是可以的,不过还是表连接的方式较好。1楼已写。
------解决方案--------------------
SQL code

select b.custname from common a left join cust b on a.ndeptcode=b.custcode  

select b.custname  from common a ,cust b where  a.ndeptcode=b.custcode