当前位置: 代码迷 >> Sql Server >> 新手初学多表查询有关问题
  详细解决方案

新手初学多表查询有关问题

热度:5   发布时间:2016-04-27 11:49:06.0
新手初学多表查询问题
现在有两个表 

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
  相关解决方案